Skip to content

Commit ff5ad18

Browse files
sadiqkhojaktuite
andauthored
Entity APIs specification (#812)
* updated API doc to reflect implementation * Docs changes related to datasets * Add list of entity endpoints to changelog, add versions endpoint * Slight rewording of docs * Fixing typos and removing name from entity odata --------- Co-authored-by: Kathleen Tuite <kathleen.tuite@gmail.com>
1 parent 86958be commit ff5ad18

File tree

1 file changed

+306
-8
lines changed

1 file changed

+306
-8
lines changed

docs/api.md

Lines changed: 306 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,24 @@ Here major and breaking changes to the API are listed by version.
3333
### ODK Central v2023.3
3434

3535
**Added**:
36+
3637
- New endpoint [PATCH /projects/:id/datasets/:name](#reference/datasets/datasets/update-dataset-metadata) to change whether approval of Submission is required to create an Entity.
38+
- New [Entities](#reference/entities) endpoints for richer Entity-Based Data Collection workflows. These endpoints provide ways of accessing Entities, as well as the ability to _create_, _update_ and _soft-delete_ Entities via the API!
39+
* New endpoint [GET /projects/:id/datasets/:name/entities](#reference/entities/retrieving-entities/entities-metadata) for listing Entities within a Dataset.
40+
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid](#reference/entities/retrieving-entities/getting-entity-details) for getting the metadata, or details, about a specific Entity.
41+
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid/versions](#reference/entities/retrieving-entities/listing-versions) for listing the versions of an Entity.
42+
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid/diffs](#reference/entities/retrieving-entities/getting-changes-between-versions) for getting the changes between versions of an Entity.
43+
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid/audits](#reference/entities/retrieving-entities/entity-audit-log) for getting the server audit logs about a specific Entity.
44+
* New endpoint [POST /projects/:id/datasets/:name/entities](#reference/entities/creating-an-entity/creating-an-entity) for creating an Entity from JSON.
45+
* New endpoint [PATCH /projects/:id/datasets/:name/entities/:uuid](#reference/entities/updating-an-entity/updating-an-entity) for updating the data or label of an Entity.
46+
* New endpoint [DELETE /projects/:id/datasets/:name/entities/:uuid](#reference/entities/deleting-an-entity/deleting-an-entity) for soft-deleting an Entity.
3747

3848
**Changed**:
49+
3950
- ETag support has been added for [Download Dataset](#reference/datasets/download-dataset/download-dataset) and [Download Form Attachment](#reference/forms/individual-form/downloading-a-form-attachment).
40-
- [Dataset Metadata endpoint](#reference/datasets/datasets/dataset-metadata) also returns sanitized property names as `odataName` to match the way they will be outputted for OData.
51+
- The format of [Download Dataset](#reference/datasets/download-dataset/download-dataset) was changed to more closely match the OData Dataset format.
52+
- In the [OData Dataset Service](#reference/odata-endpoints/odata-dataset-service), `name` was removed because it is a duplication of an `__id` representing an Entity's UUID.
53+
- The `properties` returned by the [Dataset Metadata endpoint](#reference/datasets/datasets/dataset-metadata) each now include a field `odataName`, which represents the way the property name will be sanitized and outputted for OData.
4154

4255
### ODK Central v2023.2
4356

@@ -3057,17 +3070,16 @@ By default `approvalRequired` is `false` for the Datasets created after v2023.3.
30573070

30583071
## Download Dataset [GET /projects/{projectId}/datasets/{name}/entities.csv]
30593072

3060-
Datasets (collections of Entities) can be used as Attachments in other Forms, but they can also be downloaded directly as a CSV file. The CSV format matches what is expected for a [select question](https://docs.getodk.org/form-datasets/#building-selects-from-csv-files) with columns for `name`, `label,` and properties. In the case of Datasets, the `name` column is the Entity's UUID, the `label` column is the human-readable Entity label populated in the Submission, and the properties are the full set of Dataset Properties for that Dataset. If any Property for an given Entity is blank (e.g. it was not captured by that Form or was left blank), that field of the CSV is blank.
3073+
Datasets (collections of Entities) can be used as Attachments in other Forms, but they can also be downloaded directly as a CSV file.
3074+
The CSV format closely matches the [OData Dataset Service](#reference/odata-endpoints/odata-dataset-service) format, with columns for system properties such as `__id` (the Entity UUID), `__createdAt`, `__creatorName`, etc., the Entity Label `label`, and the Dataset/Entity Properties themselves. If any Property for an given Entity is blank (e.g. it was not captured by that Form or was left blank), that field of the CSV is blank.
30613075

30623076
This endpoint supports `ETag` header, which can be used to avoid downloading the same content more than once. When an API consumer calls this endpoint, the endpoint returns a value in the ETag header. If you pass that value in the If-None-Match header of a subsequent request, then if the Dataset has not been changed since the previous request, you will receive `304 Not Modified` response; otherwise you'll get the new data.
30633077

3064-
Note that as of Version 2022.3 we do not guarantee the order of the Dataset Property columns.
30653078

30663079
```
3067-
name,label,first_name,last_name,age,favorite_color
3068-
54a405a0-53ce-4748-9788-d23a30cc3afa,Amy Aardvark,Amy,Aardvark,45,
3069-
0ee79b8b-9711-4aa0-9b7b-ece0a109b1b2,Beth Baboon,Beth,Baboon,19,yellow
3070-
3fc9c54c-7d41-4258-b014-bfacedb95711,Cory Cat,Cory,Cat,,cyan
3080+
__id,label,geometry,species,circumference_cm,__createdAt,__creatorId,__creatorName,__updates,__updatedAt
3081+
2c1ee90b-dde8-434b-9985-2eefd8465339,666cm purpleheart,-29.281608 -67.624883 0 0,purpleheart,667,2023-05-31T19:49:28.902Z,22,Alice,1,2023-05-31T19:52:34.467Z
3082+
84ac3a03-9980-4098-93a5-b81fdc6ea749,555cm wallaba,18.921876 77.309451 0 0,wallaba,555,2023-05-31T19:49:20.152Z,22,Alice,0,
30713083
```
30723084

30733085

@@ -3091,6 +3103,244 @@ name,label,first_name,last_name,age,favorite_color
30913103
+ Response 403 (application/json)
30923104
+ Attributes (Error 403)
30933105

3106+
3107+
# Group Entities
3108+
3109+
_(introduced: version 2023.3)_
3110+
3111+
Version 2023.3 brings further core enhancements to Datasets and Entities, including several new endpoints for accessing information about Entities, as well as the ability to _create_, _update_, and _soft-delete_ Entities via the API.
3112+
3113+
An Entity is a specific person, place, or thing. Datasets represent collections of Entities. More information about how to set up and use Datasets can be found in the [Datasets](#reference/datasets) section of this documentation.
3114+
3115+
## Retrieving Entities [/projects/{projectId}/datasets/{datasetName}/entities]
3116+
3117+
### Entities Metadata [GET]
3118+
This endpoint returns a list of the Entities of a Dataset. Please note that this endpoint only returns metadata of the entities not the data. If you want to get the data of all entities then please refer to [OData Dataset Service](#reference/odata-endpoints/odata-form-service)
3119+
3120+
You can provide `?deleted=true` to get only deleted entities.
3121+
3122+
+ Parameters
3123+
+ projectId: `16` (number, required) - The numeric ID of the Project
3124+
+ name: `people` (string, required) - Name of the Dataset
3125+
3126+
+ Response 200 (application/json)
3127+
This is the standard response
3128+
3129+
+ Attributes (array[Entity Summary])
3130+
3131+
+ Response 200 (application/json; extended)
3132+
This is the extended response
3133+
3134+
+ Attributes (array[Extended Entity Summary])
3135+
3136+
+ Response 403 (application/json)
3137+
+ Attributes (Error 403)
3138+
3139+
### Getting Entity Details [GET /projects/{projectId}/datasets/{name}/entities/{uuid}]
3140+
3141+
This returns the metadata and current data of an Entity
3142+
3143+
+ Parameters
3144+
+ projectId: `16` (number, required) - The numeric ID of the Project
3145+
+ name: `people` (string, required) - Name of the Dataset
3146+
+ uuid: `54a405a0-53ce-4748-9788-d23a30cc3afa` (string, required) - UUID of the Entity
3147+
3148+
+ Response 200 (application/json)
3149+
+ Attributes (Entity)
3150+
3151+
+ Response 200 (application/json; extended)
3152+
This is the extended response
3153+
3154+
+ Attributes (Extended Entity)
3155+
3156+
+ Response 403 (application/json)
3157+
+ Attributes (Error 403)
3158+
3159+
### Listing Versions [GET /projects/{projectId}/datasets/{name}/entities/{uuid}/versions]
3160+
3161+
This returns the Entity metadata and data for every version of this Entity, in ascending creation order.
3162+
3163+
This endpoint supports retrieving extended metadata; provide a header `X-Extended-Metadata: true` to return a `creator` data object alongside the `creatorId` Actor ID reference.
3164+
3165+
+ Parameters
3166+
+ projectId: `16` (number, required) - The numeric ID of the Project
3167+
+ name: `people` (string, required) - Name of the Dataset
3168+
+ uuid: `54a405a0-53ce-4748-9788-d23a30cc3afa` (string, required) - UUID of the Entity
3169+
3170+
+ Response 200 (application/json)
3171+
+ Attributes (array[Entity Version])
3172+
3173+
+ Response 200 (application/json; extended)
3174+
This is the extended response
3175+
3176+
+ Attributes (array[Extended Entity Version])
3177+
3178+
+ Response 403 (application/json)
3179+
+ Attributes (Error 403)
3180+
3181+
### Getting changes between Versions [GET /projects/{projectId}/datasets/{name}/entities/{uuid}/diffs]
3182+
3183+
This returns the changes, or edits, between different versions of an Entity. These changes are returned as an array of arrays. Between two Entities, there is an array of objects representing how each property changed. This change object contains the old and new values, as well as the property name.
3184+
3185+
+ Parameters
3186+
+ projectId: `16` (number, required) - The numeric ID of the Project
3187+
+ name: `people` (string, required) - Name of the Dataset
3188+
+ uuid: `54a405a0-53ce-4748-9788-d23a30cc3afa` (string, required) - UUID of the Entity
3189+
3190+
+ Response 200 (application/json)
3191+
+ Response 200
3192+
+ Attributes (array[array[Entity Diff Value]])
3193+
3194+
+ Body
3195+
3196+
[
3197+
[
3198+
{
3199+
"new": "John",
3200+
"old": "Dana",
3201+
"propertyName": "firstName"
3202+
},
3203+
{
3204+
"new": "Doe",
3205+
"old": "Roe",
3206+
"propertyName": "lastName"
3207+
},
3208+
{
3209+
"new": "John Doe",
3210+
"old": "Jane Roe",
3211+
"propertyName": "label"
3212+
}
3213+
],
3214+
[
3215+
{
3216+
"new": "Robert",
3217+
"old": "Doe",
3218+
"propertyName": "firstName"
3219+
},
3220+
{
3221+
"new": "Robert Doe",
3222+
"old": "Doe Doe",
3223+
"propertyName": "label"
3224+
}
3225+
]
3226+
]
3227+
3228+
+ Response 403 (application/json)
3229+
+ Attributes (Error 403)
3230+
3231+
### Entity Audit Log [GET /projects/{projectId}/datasets/{name}/entities/{uuid}/audits]
3232+
3233+
Returns [Server Audit Logs](/reference/system-endpoints/server-audit-logs) relating to an Entity. They will be returned most recent first.
3234+
3235+
+ Parameters
3236+
+ projectId: `16` (number, required) - The numeric ID of the Project
3237+
+ name: `people` (string, required) - Name of the Dataset
3238+
+ uuid: `54a405a0-53ce-4748-9788-d23a30cc3afa` (string, required) - UUID of the Entity
3239+
3240+
+ Response 200 (application/json)
3241+
+ Attributes (array[Audit])
3242+
3243+
+ Response 403 (application/json)
3244+
+ Attributes (Error 403)
3245+
3246+
## Creating an Entity [/projects/{projectId}/datasets/{name}/entities]
3247+
3248+
### Creating an Entity [POST]
3249+
Creates an Entity in the Dataset. Request body takes the JSON representation of the Entity. It should have `uuid` and `label` property in addition to the user-defined properties of the Dataset in `data` property. For e.g.
3250+
```
3251+
{
3252+
"uuid": "54a405a0-53ce-4748-9788-d23a30cc3afa",
3253+
"label": "John Doe",
3254+
"data": {
3255+
"firstName": "John",
3256+
"lastName": "Doe",
3257+
"city": "New York",
3258+
...
3259+
}
3260+
}
3261+
```
3262+
3263+
Value type of all properties is `string`.
3264+
3265+
You can provide header `X-Action-Notes` to store the metadata about the request. The metadata can retrieved using [Entity Audit Log](#reference/entities/entity-audit-log)
3266+
3267+
+ Request (application/json)
3268+
+ Attributes
3269+
+ projectId: `16` (number, required) - The numeric ID of the Project
3270+
+ name: `people` (string, required) - Name of the Dataset
3271+
3272+
+ Body
3273+
3274+
{
3275+
"uuid": "54a405a0-53ce-4748-9788-d23a30cc3afa",
3276+
"label": "John Doe",
3277+
"data": {
3278+
"firstName": "John",
3279+
"lastName": "Doe",
3280+
"city": "New York",
3281+
"...other properties": "...value of other properties"
3282+
}
3283+
}
3284+
3285+
+ Response 200 (application/json)
3286+
+ Attributes (Entity)
3287+
3288+
+ Response 200 (application/json; extended)
3289+
+ Attributes (Extended Entity)
3290+
3291+
+ Response 403 (application/json)
3292+
+ Attributes (Error 403)
3293+
3294+
## Updating an Entity [/projects/{projectId}/datasets/{name}/entities/{uuid}]
3295+
3296+
### Updating an Entity [PATCH]
3297+
Use this API to update one or all properties of an Entity. It will throw `400 - Bad Request` if any of the updating properties doesn't exist in the dataset.
3298+
3299+
To unset value of any property, you can set it to empty string (""). Setting it to `null` will throw an error.
3300+
3301+
+ Request (application/json)
3302+
+ Attributes
3303+
+ projectId: `16` (number, required) - The numeric ID of the Project
3304+
+ name: `people` (string, required) - Name of the Dataset
3305+
+ uuid: `54a405a0-53ce-4748-9788-d23a30cc3afa` (string, required) - UUID of the Entity
3306+
3307+
+ Body
3308+
3309+
{
3310+
"label": "John (88)"
3311+
"data": {
3312+
"firstName": "John",
3313+
"...other properties": "...value of other properties"
3314+
}
3315+
}
3316+
3317+
+ Response 200 (application/json)
3318+
+ Attributes (Entity)
3319+
3320+
+ Response 200 (application/json; extended)
3321+
+ Attributes (Extended Entity)
3322+
3323+
+ Response 403 (application/json)
3324+
+ Attributes (Error 403)
3325+
3326+
## Deleting an Entity [/projects/{projectId}/datasets/{name}/entities/{id}]
3327+
3328+
### Deleting an Entity [DELETE /projects/{projectId}/datasets/{name}/entities/{uuid}]
3329+
3330+
Use this API to delete an Entity. With this API, Entity is soft-deleted, which means it is still in the database and you can retreive it by passing `?deleted=true` to [GET /projects/:id/datasets/:name/entities](#reference/entities/retrieving-entities/entities-metadata). In the future, we will provide a way to restore deleted entities and purge deleted entities.
3331+
3332+
+ Parameters
3333+
+ projectId: `16` (number, required) - The numeric ID of the Project
3334+
+ name: `people` (string, required) - Name of the Dataset
3335+
+ uuid: `54a405a0-53ce-4748-9788-d23a30cc3afa` (string, required) - UUID of the Entity
3336+
3337+
+ Response 200 (application/json)
3338+
+ Attributes (Success)
3339+
3340+
+ Response 403 (application/json)
3341+
+ Attributes (Error 403)
3342+
3343+
30943344
# Group OpenRosa Endpoints
30953345

30963346
[OpenRosa](https://bitbucket.org/javarosa/javarosa/wiki/OpenRosaAPI) is an API standard which accompanies the ODK XForms XML standard, allowing compliant servers and clients to use a common protocol to communicate `Form`s and `Submission`s to each other. When survey clients like ODK Collect and Enketo submit Submission data to a Form, this is the API they use.
@@ -3763,6 +4013,8 @@ The Metadata Document describes, in [EDMX CSDL](http://docs.oasis-open.org/odata
37634013
<Property Name="createdAt" Type="Edm.DateTimeOffset"/>
37644014
<Property Name="creatorId" Type="Edm.String"/>
37654015
<Property Name="creatorName" Type="Edm.String"/>
4016+
<Property Name="updates" Type="Edm.Int64"/>
4017+
<Property Name="updatedAt" Type="Edm.DateTimeOffset"/>
37664018
</ComplexType>
37674019
</Schema>
37684020
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="org.opendatakit.user.trees">
@@ -4607,4 +4859,50 @@ These are in alphabetic order, with the exception that the `Extended` versions o
46074859
+ name: `the.age` (string, required) - The name of the Property.
46084860
+ odataName: `the_age` (string, required) - The name of the property as it will appear in OData. OData property names can only contain alphanumeric characters and underscores.
46094861
+ publishedAt: `2018-01-21T00:04:11.153Z` (string, required) - Publishing timestamp of the form that defined this property for the first time.
4610-
+ forms: (array[Form KeyValue]) - List of forms that create the property
4862+
+ forms: (array[Form KeyValue]) - List of forms that create the property
4863+
4864+
## Entity Summary Fields (object)
4865+
+ uuid: `uuid:85cb9aff-005e-4edd-9739-dc9c1a829c44` (string, required) - The `uuid` of the Entity that uniquely identifies the Entity.
4866+
+ createdAt: `2018-01-19T23:58:03.395Z` (string, required) - ISO date format. The time that the server received the Entity.
4867+
+ updatedAt: `2018-03-21T12:45:02.312Z` (string, optional) - Timestamp of the last update in ISO date format. `null` when there is only one version of the Entity.
4868+
+ deletedAt: `2018-03-21T12:45:02.312Z` (string, optional) - Timestamp of the deletion in ISO date format. `null` if the Entity is not deleted.
4869+
+ creatorId: `1` (number, required) - The ID of the Actor (App User, User, or Public Link) that originally created the Entity.
4870+
4871+
## Entity Version Fields (object)
4872+
+ label: `John (88)` (string, required) - Label of the Entity
4873+
+ current: `true` (boolean, required) - `true` if the version is the latest one
4874+
+ createdAt: `2018-03-21T12:45:02.312Z` (string, required) - Timestamp in ISO format
4875+
+ creatorId: `1` (number, required) - The ID of the Actor (App User, User, or Public Link) that created this version.
4876+
+ userAgent: `Enketo/3.0.4` (string, optional) - The self-identified `userAgent` of the device that created the `Entity` version.
4877+
4878+
## Extended Entity Version Summary (Entity Version Fields)
4879+
+ creator: (Actor, required) - The full details of the Actor that created the Entity.
4880+
4881+
## Entity Summary (Entity Summary Fields)
4882+
+ currentVersion: (Entity Version Fields, required) - Current version of the Entity
4883+
4884+
## Extended Entity Summary (Entity Summary Fields)
4885+
+ creator: (Actor, required) - The full details of the Actor that created the Entity.
4886+
+ currentVersion: (Extended Entity Version Summary, required) - Current version of the Entity
4887+
4888+
## Entity (Entity Summary Fields)
4889+
+ currentVersion: (Entity Version, required) - Current version of the Entity
4890+
4891+
## Extended Entity (Entity Summary Fields)
4892+
+ creator: (Actor, required) - The full details of the Actor that created the Entity.
4893+
+ currentVersion: (Extended Entity Version, required) - Current version of the Entity
4894+
4895+
## Entity Version (Entity Version Fields)
4896+
+ data: (Data Example, required) - Data of the Entity
4897+
4898+
## Extended Entity Version (Entity Version)
4899+
+ creator: (Actor, required) - The full details of the Actor that created the Entity.
4900+
4901+
## Entity Diff Value (object)
4902+
+ new (string, nullable) - The new value of this property.
4903+
+ old (string, nullable) - The old value of this property.
4904+
+ propertyName (array) - The name of the property that is changed.
4905+
4906+
## Data Example (object)
4907+
+ firstName: `John` (string, required)
4908+
+ age: `88` (string, required)

0 commit comments

Comments
 (0)