Skip to content

Commit 983ec81

Browse files
authored
Review and polish of 2023.5 API docs (#1068)
* Review and polish of 2023.5 api docs * Add version and conflict to odata entity schema in docs * Change description of conflicts
1 parent 222a183 commit 983ec81

File tree

3 files changed

+77
-22
lines changed

3 files changed

+77
-22
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Instead of `make dev`, run both `make dev-oidc` and `make fake-oidc-server`.
2828

2929
We use OpenAPI specification for API documentation. It is located at `docs/api.yaml`.
3030

31-
You can run `make api-docs` to preview the document.
31+
You can run `make api-docs` to preview the document. This will use Docker to build the entire Central docs, which contain the API docs under the "Developers" section.
3232

3333
## Guidelines
3434

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ A number of operational tasks (creating accounts, setting passwords, etc) may be
2424

2525
### Accessing the API
2626

27-
ODK Central Backend is, first and foremost, a RESTful HTTP API server that manages Users, Forms, Submissions, and other objects necessary to run an ODK data collection campaign. This API is used by the bundled frontend web interface to form a complete user-installable server solution, but that API can also be used on its own with or without the frontend to programmatically manage a data collection project. We provide a full documentation of the API in the standard [OpenAPI](https://www.openapis.org/) format. You can find a plain version of that documentation [here](https://github.com/getodk/central-backend/blob/master/docs/api.yaml) in the repository, or you can access the [published version](https://docs.getodk.org/central-api/) for a friendlier interface.
27+
ODK Central Backend is, first and foremost, a RESTful HTTP API server that manages Users, Forms, Submissions, and other objects necessary to run an ODK data collection campaign. This API is used by the bundled frontend web interface to form a complete user-installable server solution, but that API can also be used on its own with or without the frontend to programmatically manage a data collection project.
28+
29+
We provide a full documentation of the API in the standard [OpenAPI](https://www.openapis.org/) format. You can find a plain version of that documentation [here](https://github.com/getodk/central-backend/blob/master/docs/api.yaml) in the repository, or you can access the [published version](https://docs.getodk.org/central-api/) for a friendlier interface. Please see the [makefile](Makefile) and [Contribution Guide](https://github.com/getodk/central-backend/blob/master/CONTRIBUTING.md) for information on building the documentation locally.
2830

2931
## Setting up a development environment
3032

docs/api.yaml

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,27 @@ info:
4040

4141
**Added**:
4242

43-
- Entities accessed via API now have conflict and version-specific conflictingProperties fields
43+
- Central now supports _Entity Updates via Submissions_ as part of our continued work on Entity-Based Data Collection!
44+
* Submissions for Entity Updates specify which properties/label to update with new values and an Entity's target `baseVersion`, which is used to track conflicts
45+
- Entities accessed via the API have additional information about conflicts (when multiple Submissions update the same Entity)
46+
* Each [Entity](/central-api-entity-management/#getting-entity-details) now has a `conflict` field, which is either:
47+
* `null`. The Entity does not have conflicting versions.
48+
* `soft`. The Entity has a version that was based on a version other than the version immediately prior to it. (The specified `baseVerson` was not the latest version on the server.)
49+
* `hard`. The Entity has a version that was based on a version other than the version immediately prior to it. Further, that version updated the same property as another update.
50+
* If an Entity has a conflict, it can be marked as resolved. After that, the conflict field will be null until a new conflicting version is received.
51+
* Each Entity Version (`currentVersion` or list of versions) has new fields `baseVersion`, `dataReceived`, and `conflictingProperties`
52+
- [Datasets](/central-api-dataset-management/#datasets) extended metadata now has a `conflicts` field, which counts number of Entities currently in conflict
53+
- Entity conflicts can be resolved using the existing [PATCH](/central-api-entity-management/#updating-an-entity) endpoint, with or without new data
54+
- New `relevantToConflict` query parameter on [GET entities/:uuid/versions](/central-api-entity-management/#listing-versions)
4455

45-
* Conflicts are either `hard` (baseVersion conflicts and multiple versions update the same property), `soft` (baseVersion conflicts but data updates are independent), or `null`
4656

4757
**Changed**:
4858

49-
- Conflicts can be resolved using the [PATCH entity](/central-api-entity-management/#updating-an-entity) endpoint with or without new data
59+
- Dataset entity list [entities.csv](/central-api-dataset-management/#download-dataset) can now be filtered
60+
- Entity Update [PATCH](/central-api-entity-management/#updating-an-entity) endpoint now expects `baseVersion` query parameter or `force` flag
5061

51-
### ODK Central v2023.4
62+
63+
## ODK Central v2023.4
5264

5365
**Added**:
5466

@@ -67,14 +79,14 @@ info:
6779
- New endpoint [PATCH /projects/:id/datasets/:name](/central-api-dataset-management/#update-dataset-metadata) to change whether approval of Submission is required to create an Entity.
6880
- New [Entities](/central-api-entity-management) 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!
6981

70-
* New endpoint [GET /projects/:id/datasets/:name/entities](/central-api-entities/#entities-metadata) for listing Entities within a Dataset.
71-
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid](/central-api-entities/#getting-entity-details) for getting the metadata, or details, about a specific Entity.
72-
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid/versions](/central-api-entities/#listing-versions) for listing the versions of an Entity.
73-
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid/diffs](/central-api-entities/#getting-changes-between-versions) for getting the changes between versions of an Entity.
74-
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid/audits](/central-api-entities/#entity-audit-log) for getting the server audit logs about a specific Entity.
75-
* New endpoint [POST /projects/:id/datasets/:name/entities](/central-api-entities/#creating-an-entity) for creating an Entity from JSON.
76-
* New endpoint [PATCH /projects/:id/datasets/:name/entities/:uuid](/central-api-entities/#updating-an-entity) for updating the data or label of an Entity.
77-
* New endpoint [DELETE /projects/:id/datasets/:name/entities/:uuid](/central-api-entities/#deleting-an-entity) for soft-deleting an Entity.
82+
* New endpoint [GET /projects/:id/datasets/:name/entities](/central-api-entity-management/#entities-metadata) for listing Entities within a Dataset.
83+
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid](/central-api-entity-management/#getting-entity-details) for getting the metadata, or details, about a specific Entity.
84+
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid/versions](/central-api-entity-management/#listing-versions) for listing the versions of an Entity.
85+
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid/diffs](/central-api-entity-management/#getting-changes-between-versions) for getting the changes between versions of an Entity.
86+
* New endpoint [GET /projects/:id/datasets/:name/entities/:uuid/audits](/central-api-entity-management/#entity-audit-log) for getting the server audit logs about a specific Entity.
87+
* New endpoint [POST /projects/:id/datasets/:name/entities](/central-api-entity-management/#creating-an-entity) for creating an Entity from JSON.
88+
* New endpoint [PATCH /projects/:id/datasets/:name/entities/:uuid](/central-api-entity-management/#updating-an-entity) for updating the data or label of an Entity.
89+
* New endpoint [DELETE /projects/:id/datasets/:name/entities/:uuid](/central-api-entity-management/#deleting-an-entity) for soft-deleting an Entity.
7890

7991
**Changed**:
8092

@@ -9853,6 +9865,8 @@ paths:
98539865

98549866
The CSV format closely matches the [OData Dataset Service](/central-api-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.
98559867

9868+
The `$filter` querystring parameter can be used to filter on system-level properties, similar to how filtering in the [OData Dataset Service](/central-api-odata-endpoints/#odata-dataset-service) works.
9869+
98569870
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.
98579871
operationId: Download Dataset
98589872
parameters:
@@ -9870,6 +9884,12 @@ paths:
98709884
schema:
98719885
type: string
98729886
example: people
9887+
- name: $filter
9888+
in: query
9889+
description: If provided, will filter responses to those matching the query. Only system-level Entity fields are available to reference. The operators `lt`, `le`, `eq`, `neq`, `ge`, `gt`, `not`, `and`, and `or` are supported, and the built-in functions `now`, `year`, `month`, `day`, `hour`, `minute`, `second`.
9890+
schema:
9891+
type: string
9892+
example: __system/conflict eq \'hard\'
98739893
responses:
98749894
200:
98759895
description: OK
@@ -10015,7 +10035,7 @@ paths:
1001510035

1001610036
Value type of all properties is `string`.
1001710037

10018-
You can provide header `X-Action-Notes` to store the metadata about the request. The metadata can retrieved using [Entity Audit Log](/central-api-entities/#entity-audit-log)
10038+
You can provide header `X-Action-Notes` to store the metadata about the request. The metadata can retrieved using [Entity Audit Log](/central-api-entity-management/#entity-audit-log)
1001910039
operationId: Creating an Entity
1002010040
parameters:
1002110041
- name: projectId
@@ -10093,7 +10113,21 @@ paths:
1009310113
tags:
1009410114
- Entity Management
1009510115
summary: Getting Entity Details
10096-
description: This returns the metadata and current data of an Entity
10116+
description: |-
10117+
This returns the metadata and current data of an Entity.
10118+
10119+
The data and label of an Entity are found in the `currentVersion` object under `data` and `label` respectively. The `currentVersion` object also contains version-specific metadata fields such as `version`, `baseVersion`, details about conflicts that version introduced, etc. See the [versions](/central-api-entity-management/#listing-versions) endpoint for more details.
10120+
10121+
The Entity also contains top-level system metadata such as `uuid`, `createdAt` and `updatedAt` timestamps, and `creatorId` (or full `creator` if extended metadata is requested).
10122+
10123+
**Conflicts**
10124+
10125+
An Entity's metadata also has a `conflict` field, which indicates the current conflict status of the Entity. The value of a conflict can either be:
10126+
* `null`. The Entity does not have conflicting versions.
10127+
* `soft`. The Entity has a version that was based on a version other than the version immediately prior to it. (The specified `baseVerson` was not the latest version on the server.)
10128+
* `hard`. The Entity has a version that was based on a version other than the version immediately prior to it. Further, that version updated the same property as another update.
10129+
10130+
If an Entity has a conflict, it can be marked as resolved. After that, the conflict field will be null until a new conflicting version is received.
1009710131
operationId: Getting Entity Details
1009810132
parameters:
1009910133
- name: projectId
@@ -10224,7 +10258,7 @@ paths:
1022410258
summary: Deleting an Entity
1022510259
description: Use this API to delete an Entity. With this API, Entity is soft-deleted,
1022610260
which means it is still in the database and you can retreive it by passing
10227-
`?deleted=true` to [GET /projects/:id/datasets/:name/entities](/central-api-entities/#entities-metadata).
10261+
`?deleted=true` to [GET /projects/:id/datasets/:name/entities](/central-api-entity-management/#entities-metadata).
1022810262
In the future, we will provide a way to restore deleted entities and purge
1022910263
deleted entities.
1023010264
operationId: Deleting an Entity
@@ -10279,13 +10313,15 @@ paths:
1027910313
- Entity Management
1028010314
summary: Updating an Entity
1028110315
description: |-
10282-
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.
10316+
This endpoint is used to update the label or the properties (passed as JSON in the request body) of an Entity. You only need to include the properties you wish to update. To unset the value of any property, you can set it to empty string (""). The label must be a non-empty string. Setting a property to `null` will throw an error. Attempting to update a property that doesn't exist in the Dataset will throw an error.
1028310317

10284-
To unset value of any property, you can set it to empty string (""). Setting it to `null` will throw an error.
10318+
**Specifying a base version**
1028510319

10286-
**Resolve the conflict**
10320+
You must either provide the query parameter `baseVersion` or use the `force=true` query paramater. You cannot cause a new Entity conflict via the API, which is why when specifying `baseVersion`, it must match the current version of the Entity on the server. This acts as a check to ensure you are not trying to update based on stale data. If you wish to update the Entity regardless of the current state, then you can use the `force` flag.
1028710321

10288-
You can also use this endpoint to resolve the conflict by passing `resolve=true` query parameter. If you set `resolve` parameter then providing data in the body is optional, in that case only `conflict` status from the Entity will be cleared.
10322+
**Resolving a conflict**
10323+
10324+
You can also use this endpoint to resolve an Entity conflict by passing the `resolve=true` query parameter, in which case providing data in the request body is optional. When not providing new data, only the `conflict` status from the Entity will be cleared and no new version will be created. When providing data, the `conflict` will be cleared and an updated version of the Entity will be added.
1028910325
operationId: Updating an Entity
1029010326
parameters:
1029110327
- name: projectId
@@ -10309,6 +10345,13 @@ paths:
1030910345
schema:
1031010346
type: string
1031110347
example: 54a405a0-53ce-4748-9788-d23a30cc3afa
10348+
- name: baseVersion
10349+
in: query
10350+
description: The base version of the Entity you are applying the update to (must match the latest version on the server)
10351+
required: false
10352+
schema:
10353+
type: integer
10354+
example: 2
1031210355
- name: force
1031310356
in: query
1031410357
description: Flag to forcefully update the Entity
@@ -10406,6 +10449,8 @@ paths:
1040610449
This returns the Entity metadata and data for every version of this Entity, in ascending creation order.
1040710450

1040810451
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.
10452+
10453+
There is an optional query flag `relevantToConflict` that returns the subset of past versions of an Entity that are relevant to the Entity's current conflict. This includes the latest version, the base version, the previous server version, and any other versions since the last time the Entity was in a conflict-free state. If the Entity is not in conflict, zero versions are returned.
1040910454
operationId: Listing Entity Versions
1041010455
parameters:
1041110456
- name: projectId
@@ -10429,6 +10474,12 @@ paths:
1042910474
schema:
1043010475
type: string
1043110476
example: 54a405a0-53ce-4748-9788-d23a30cc3afa
10477+
- name: relevantToConflict
10478+
in: query
10479+
description: Flag to return only the versions of the entity that are relevant to the current conflict.
10480+
schema:
10481+
type: boolean
10482+
example: true
1043210483
responses:
1043310484
200:
1043410485
description: OK
@@ -11859,6 +11910,8 @@ paths:
1185911910
<Property Name="creatorName" Type="Edm.String"/>
1186011911
<Property Name="updates" Type="Edm.Int64"/>
1186111912
<Property Name="updatedAt" Type="Edm.DateTimeOffset"/>
11913+
<Property Name="version" Type="Edm.Int64"/>
11914+
<Property Name="conflict" Type="Edm.String"/>
1186211915
</ComplexType>
1186311916
</Schema>
1186411917
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="org.opendatakit.user.trees">
@@ -11983,7 +12036,7 @@ paths:
1198312036

1198412037
The `$top` and `$skip` querystring parameters, specified by OData, apply `limit` and `offset` operations to the data, respectively. The `$count` parameter, also an OData standard, will annotate the response data with the total row count, regardless of the scoping requested by `$top` and `$skip`. If `$top` parameter is provided in the request then the response will include `@odata.nextLink` that you can use as is to fetch the next set of data.
1198512038

11986-
The [`$filter` querystring parameter](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#_Toc31358948)can be used to filter by any data field in the system-level schema, but not the Dataset properties. The operators `lt`, `le`, `eq`, `ne`, `ge`, `gt`, `not`, `and`, and `or` are supported. The built-in functions `now`, `year`, `month`, `day`, `hour`, `minute`, `second` are supported.
12039+
The [`$filter` querystring parameter](http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#_Toc31358948) can be used to filter by any data field in the system-level schema, but not the Dataset properties. The operators `lt`, `le`, `eq`, `ne`, `ge`, `gt`, `not`, `and`, and `or` are supported. The built-in functions `now`, `year`, `month`, `day`, `hour`, `minute`, `second` are supported.
1198712040

1198812041
The fields you can query against are as follows:
1198912042

0 commit comments

Comments
 (0)