Skip to content

Commit 8d95309

Browse files
wp0pwSteveLasker
andauthored
Update docs with events /search endpoint (#988)
* AB#10424 update docs with events /search endpoint * spelling and formatting * Complete formatting and examples for baseline filtering and paging of events Co-authored-by: steve lasker <[email protected]> Signed-off-by: steve lasker <[email protected]>
1 parent 2b2631f commit 8d95309

File tree

1 file changed

+118
-16
lines changed
  • content/developers/api-reference/events-api

1 file changed

+118
-16
lines changed

content/developers/api-reference/events-api/index.md

Lines changed: 118 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ To minimize the impact, prior to switching to Asset-free Events, it is recommend
3131

3232
## Events API Examples
3333

34-
{{< note >}}
35-
**Note:** If you are looking for a simple way to test DataTrails APIs you might prefer the [Postman collection](https://www.postman.com/datatrails-inc/workspace/datatrails-public/overview), the [YAML runner](/developers/yaml-reference/story-runner-components/) or the [Developers](https://app.datatrails.ai) section of the web UI.
36-
37-
Additional YAML examples can be found in the articles in the [Overview](/platform/overview/introduction/) section.
38-
{{< /note >}}
39-
4034
### Event Creation
4135

4236
- Create the [bearer_token](/developers/developer-patterns/getting-access-tokens-using-app-registrations) and store in a file in a secure local directory with 0600 permissions.
@@ -157,14 +151,11 @@ To associate an Attachment with an Event, see the [Attachments API](/developers/
157151
158152
Event records in DataTrails are assigned UUIDs at creation time and referred to in all future API calls by a their unique identity in the format: `events/<event-id>`
159153
160-
{{< note >}}
161-
**Note:** The current preview limits fetching Events to the Event identity.
162-
Querying across event attributes and trails are coming in a future preview.
163-
{{< /note >}}
154+
## Fetch Events by Identity
164155
165-
#### Fetch Events by Identity
166-
167-
- Replace the `<event-id>` below, using the event-id from the created event above: `"identity": "events/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"`:
156+
- Replace the `<event-id>` below, using the event-id from the created event above.
157+
`"identity": "events/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"`:
158+
Note, "`events/`" must be included as it's part of the resource name:
168159
169160
```bash
170161
EVENT_ID=<event-id>
@@ -175,13 +166,124 @@ Querying across event attributes and trails are coming in a future preview.
175166
```bash
176167
curl -X GET \
177168
-H "@$HOME/.datatrails/bearer-token.txt" \
178-
"https://app.datatrails.ai/archivist/v1/events/$EVENT_ID" | jq
169+
"https://app.datatrails.ai/archivist/v1/$EVENT_ID" | jq
179170
```
180171
181-
## Events OpenAPI Docs
172+
## Filtering and Paging Events
182173
183-
{{< openapi url="https://raw.githubusercontent.com/datatrails/datatrails-openapi/main/doc/events.swagger.json" >}}
174+
- To fetch multiple events, use a search document, posting to the `/events/search` endpoint
175+
Search document has following form:
176+
177+
```bash
178+
cat > /tmp/search.json <<EOF
179+
{
180+
"filter": "",
181+
"top": 20,
182+
"skip": 0
183+
}
184+
EOF
185+
```
186+
187+
where:
188+
`filter` = attribute name/value pairs
189+
`top` = number of results to return (max. 50) and
190+
`skip` = how many results to skip over before returning set of results
191+
192+
{{< note >}}
193+
**Note:** The current preview does not support filtering of Events.
194+
Filtering across event attributes and trails are coming in a future preview.
195+
{{< /note >}}
196+
197+
- Post `search.json` to the `/search` endpoint:
198+
199+
```bash
200+
curl -X POST \
201+
-H "@$HOME/.datatrails/bearer-token.txt" \
202+
-d "@/tmp/search.json" \
203+
"https://app.datatrails.ai/archivist/v1/events/search" \
204+
| jq
205+
```
206+
207+
- The response will include a list of events matching above criteria:
208+
209+
```json
210+
{
211+
"events": [
212+
{
213+
"identity": "events/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
214+
"attributes": {
215+
"inspector": "Clouseau",
216+
"arc_display_type": "Safety Conformance",
217+
"Safety Rating": "90"
218+
},
219+
"trails": [
220+
"Safety Conformance",
221+
"Clouseau"
222+
],
223+
"origin_tenant": "tenant/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
224+
"created_by": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
225+
"created_at": 1736421833577,
226+
"confirmation_status": "STORED",
227+
"merklelog_commit": {
228+
"index": "0",
229+
"idtimestamp": ""
230+
}
231+
},
232+
{
233+
"identity": "events/yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy",
234+
"attributes": {
235+
"inspector": "Clouseau",
236+
"arc_display_type": "Safety Conformance",
237+
"Safety Rating": "99"
238+
},
239+
"trails": [
240+
"Safety Conformance",
241+
"Clouseau"
242+
],
243+
"origin_tenant": "tenant/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
244+
"created_by": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
245+
"created_at": 1736421873579,
246+
"confirmation_status": "STORED",
247+
"merklelog_commit": {
248+
"index": "0",
249+
"idtimestamp": ""
250+
}
251+
}
252+
]
253+
}
254+
```
255+
256+
### Fetch Paged Results
257+
258+
Use `top` and `skip` alongside `x-total-count` response header to navigate results.
259+
If sum of `skip` and number of results in response is less than the count of all results (`x-total-count` in the response header) there are more results to retrieve.
260+
To get the next set of results, re-issue the `/search` request with `skip` increased by number of results in current response.
261+
262+
If `x-total-count` response header has value greater than 2 (as indicated by value of `top` in `search.json`) modify `search.json` to the following:
263+
264+
```bash
265+
cat > /tmp/search.json <<EOF
266+
{
267+
"filter": "",
268+
"top": 2,
269+
"skip": 2
270+
EOF
271+
```
272+
273+
- Post to the `/events/search/` endpoint to retrieve another page of results, repeating this process until `skip` + number or results in the response is equal to `x-total-count`.
274+
275+
```bash
276+
curl -X POST \
277+
-H "@$HOME/.datatrails/bearer-token.txt" \
278+
-d /tmp/search.json \
279+
"https://app.datatrails.ai/archivist/v1/events/search" \
280+
| jq
281+
```
184282
185283
## Integrity Protecting Content
186284
187285
Integrity protected content can be hashed within an Event using the [Attachments API](/developers/api-reference/attachments-api/).
286+
287+
## Events OpenAPI Docs
288+
289+
{{< openapi url="https://raw.githubusercontent.com/datatrails/datatrails-openapi/main/doc/events.swagger.json" >}}

0 commit comments

Comments
 (0)