View source: R/entity_create.R
entity_create | R Documentation |
entity_create(
pid = get_default_pid(),
did = "",
label = "",
uuid = "",
notes = "",
data = list(),
url = get_default_url(),
un = get_default_un(),
pw = get_default_pw(),
retries = get_retries(),
odkc_version = get_default_odkc_version(),
orders = get_default_orders(),
tz = get_default_tz()
)
pid |
The numeric ID of the project, e.g.: 2. Default: Set default See |
did |
(chr) The name of the Entity List, internally called Dataset. The function will error if this parameter is not given. Default: "". |
label |
(character) The Entity label which must be a non-empty string.
If the label is given, a single entity is created using |
uuid |
(character) A single UUID to assign to the entity.
Default: |
notes |
(character) Metadata about the request which can be retrieved
using the entity audit log.
Default: |
data |
(list) A named list of Entity properties to create a single
Entity, or a nested list with an array of Entity data to create multiple
Entities. The nested lists representing individual entities must be valid
as in they must contain a label, valid data for the respective entity
properties, and can contain an optional UUID.
See details and the ODK documentation for the exact format.
Default: |
url |
The ODK Central base URL without trailing slash. Default: Set default See |
un |
The ODK Central username (an email address).
Default: |
pw |
The ODK Central password.
Default: |
retries |
The number of attempts to retrieve a web resource. This parameter is given to Default: 3. |
odkc_version |
The ODK Central version as a semantic version string
(year.minor.patch), e.g. "2023.5.1". The version is shown on ODK Central's
version page Default: Set default See |
orders |
(vector of character) Orders of datetime elements for lubridate. Default:
|
tz |
A timezone to convert dates and times to. Read |
For creating a single Entity, include
An optional uuid
. If skipped, Central will create a UUID for the Entity.
The Entity label
must be non-empty.
A named list data
representing the Entity's fields. The value type of
all properties is string.
uuid = "..."
label = "John Doe"
data = list("firstName" = "John", "age" = "22")
This translates to JSON
{ "label": "John Doe", "data": { "firstName": "John", "age": "22" } }
For creating multiple Entities in bulk, the request body takes an array entities containing a list of Entity objects as described above. The bulk entity version also takes a source property with a required name field and optional size, for example to capture the file name and size of a bulk upload source (in MB).
data=list( "entities" = c( list("label" = "Entity 1", "data" = list("field1" = "value1")), list("label" = "Entity 2", "data" = list("field1" = "value2")) ), "source" = list("name" = "file.csv", "size" = 100) )
This translates to JSON
{ "entities": [...], "source": {"name": "file.csv", "size": 100} }
You can provide notes
to store the metadata about the request.
The metadata is included in the POST request as header X-Action-Notes
and
can retrieved using Entity Audit Log.
A nested list identical to the return value of entity_detail
.
See https://docs.getodk.org/central-api-entity-management/#creating-entities
for the full schema.
Top level list elements are renamed from ODK's camelCase
to snake_case
.
Nested list elements have the original camelCase
.
https://docs.getodk.org/central-api-entity-management/#creating-entities
Other entity-management:
entity_audits()
,
entity_changes()
,
entity_delete()
,
entity_detail()
,
entity_list()
,
entity_update()
,
entity_versions()
,
entitylist_detail()
,
entitylist_download()
,
entitylist_list()
,
entitylist_update()
,
odata_entitylist_data_get()
,
odata_entitylist_metadata_get()
,
odata_entitylist_service_get()
## Not run:
# See vignette("setup") for setup and authentication options
# ruODK::ru_setup(svc = "....svc", un = "me@email.com", pw = "...")
el <- entitylist_list()
# Entity List name (dataset ID, did)
did <- el$name[1]
# All Entities of Entity List
en <- entity_list(did = did)
# Create a single entity
ec <- entity_create(
did = did,
label = "Entity label",
notes = "Metadata about the created entity",
data = list("field1" = "value1", "field2" = "value1")
)
ec
# Create multiple entities, example: test form "problems"
label <- c(
glue::glue(
"Entity {nrow(en) + 1} created by ruODK package test on {Sys.time()}"
),
glue::glue(
"Entity {nrow(en) + 2} created by ruODK package test on {Sys.time()}"
)
)
notes <- glue::glue("Two entities created by ruODK package test on {Sys.time()}")
status <- c("needs_followup", "needs_followup")
details <- c("ruODK package test", "ruODK package test")
geometry <- c("-33.2 115.0 0.0 0.0", "-33.2 115.0 0.0 0.0")
data <- data.frame(status, details, geometry, stringsAsFactors = FALSE)
request_data <- list(
"entities" = data.frame(label, data = I(data), stringsAsFactors = FALSE),
"source" = list("name" = "file.csv", "size" = 100)
)
# Compare request_data to the schema expected by Central
# https://docs.getodk.org/central-api-entity-management/#creating-entities
# jsonlite::toJSON(request_data, pretty = TRUE, auto_unbox = TRUE)
ec <- entity_create(
did = did,
notes = notes,
data = request_data
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.