Skip to content

Commit

Permalink
Release new feed endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
MaximeGoyette committed Sep 27, 2024
1 parent 69d0ea5 commit ef9d6b4
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 143 deletions.
4 changes: 2 additions & 2 deletions docs/api-reference/v4/endpoints/current-tenant-feed.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Current Tenant Feed"
title: "List Tenant Events"
api: "POST https://api.flare.io/firework/v4/events/tenant/_search"
---

Expand Down Expand Up @@ -57,7 +57,7 @@ This endpoint supports the
## Guides

See the guide for using this endpoint:
[Exporting a Tenant's Events <Icon icon="book" size={16} />](/guides/tenant-events-api-v4).
[Exporting a Tenant's Events <Icon icon="book" size={16} />](/guides/tenant-events).

## Body Parameters

Expand Down
4 changes: 2 additions & 2 deletions docs/api-reference/v4/endpoints/identifier-feed.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Identifier Feed"
title: "List Identifier Events"
api: "POST https://api.flare.io/firework/v4/events/identifiers/{identifier_id}/_search"
---

Expand Down Expand Up @@ -57,7 +57,7 @@ This endpoint supports the
## Guides

See the guide for using this endpoint:
[Exporting a Tenant's Events <Icon icon="book" size={16} />](/guides/tenant-events-api-v4).
[Exporting a Tenant's Events <Icon icon="book" size={16} />](/guides/tenant-events).

## Path Parameters

Expand Down
4 changes: 2 additions & 2 deletions docs/api-reference/v4/endpoints/identifier-group-feed.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: "Identifier Group Feed"
title: "List Identifier Group's Events"
api: "POST https://api.flare.io/firework/v4/events/identifier_groups/{identifier_group_id}/_search"
---

Expand Down Expand Up @@ -57,7 +57,7 @@ This endpoint supports the
## Guides

See the guide for using this endpoint:
[Exporting a Tenant's Events <Icon icon="book" size={16} />](/guides/tenant-events-api-v4).
[Exporting a Tenant's Events <Icon icon="book" size={16} />](/guides/tenant-events).

## Path Parameters

Expand Down
117 changes: 0 additions & 117 deletions docs/guides/tenant-events-api-v4.mdx

This file was deleted.

77 changes: 60 additions & 17 deletions docs/guides/tenant-events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,12 @@ title: 'List Events Within a Tenant'
---

Browsing events within a tenant is exposed through the
[/me/feed <Icon icon="code" size={16} />](/api-reference/v2/endpoints/me/get-mefeed)
[List Tenant Events <Icon icon="code" size={16} />](/api-reference/v4/endpoints/current-tenant-feed)
API.

This guide explains how to use the tenant feed API perform a full export
of all results.

## Parameters

| Parameter | Value | Justification |
| --------- | ----- | ------------- |
| lite | false | Retrieve all event fields. This will result in larger response payloads. |
| order | asc | Retrieve results in ascending order so that we can resume fetching in the future. |
| sort_by | searchable | Sort results in the order that they have been added to Flare's database. |

## Paging

The tenant feed endpoint uses parameters that match the
Expand All @@ -25,8 +17,12 @@ The tenant feed endpoint uses parameters that match the
## Fetching new results in future executions

It is possible to save the `next` in a database and use it to resume fetching new results in the future.
However, it is important that future requests use the same parameters for everything else but `next`. Even the time filter.
However, it is important that future requests use **exactly** the same parameters for everything else but `next`.

## Getting the full data of results

For performance reasons, feed results only contain the bear minimum.
To get the full data, an API call must be made per result to the [Retrieve Event <Icon icon="code" size={16} />](/api-reference/v2/endpoints/activities/get-activities) endpoint.

<AccordionGroup>

Expand All @@ -48,13 +44,10 @@ last_from: str | None = None
fetched_pages: int = 0

for resp in api_client.scroll(
method="GET",
url="/firework/v2/me/feed",
params={
"lite": "false",
"order": "asc",
"sort_by": "searchable",
"from": None,
method="POST",
url="/firework/v4/events/tenant/_search",
json={
"from": last_from,
}
):
# Rate limiting.
Expand All @@ -68,7 +61,57 @@ for resp in api_client.scroll(

# Save the last "next" value.
last_from = resp_data.get("next") or last_from

# Get the full data
for item in resp_data["items"]:
# Rate limiting.
time.sleep(1)

item_uid: str = item["metadata"]["uid"]
response = api_client.get(f"/firework/v2/activities/{item_uid}")
full_data = response.json()
print(f"Here is the full data of the event: {full_data}")
```
</Accordion>

</AccordionGroup>

## List events for a single identifier

If you're looking to export the events of a single identifier, refer to the [List Identifier Events <Icon icon="code" size={16} />](/api-reference/v4/endpoints/identifier-feed) endpoint.

```python
# (incomplete example)

# ID of the identifier for which we want to list the events.
identifier_id: int = 12345

for resp in api_client.scroll(
method="POST",
url=f"/firework/v4/events/identifiers/{identifier_id}/_search",
json={
"from": last_from,
}
):
...
```

## List events for an identifier group

If you're looking to export the events of an entire identifier group, refer to the [List Identifier Group's Events <Icon icon="code" size={16} />](/api-reference/v4/endpoints/identifier-group-feed) endpoint.

```python
# (incomplete example)

# ID of the identifier group for which we want to list the events.
identifier_group_id: int = 12345

for resp in api_client.scroll(
method="POST",
url=f"/firework/v4/events/identifier_groups/{identifier_group_id}/_search",
json={
"from": last_from,
}
):
...
```
6 changes: 3 additions & 3 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@
{
"group": "Event Feeds",
"pages": [
"api-reference/v2/endpoints/me/get-mefeed",
"api-reference/v4/endpoints/current-tenant-feed",
"api-reference/v2/endpoints/me/get-mefeedcredentials",
"api-reference/v2/endpoints/identifiers/get-assets-feed",
"api-reference/v2/endpoints/identifiers/get-assetsgroups-feed"
"api-reference/v4/endpoints/identifier-feed",
"api-reference/v4/endpoints/identifier-group-feed"
]
},
{
Expand Down

0 comments on commit ef9d6b4

Please sign in to comment.