-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from Flared/max/new-guide-tenant-events
Add new guide to fetch tenant events
- Loading branch information
Showing
3 changed files
with
82 additions
and
9 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
.../endpoints/activities/get-activities-.mdx → ...2/endpoints/activities/get-activities.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--- | ||
openapi: firework-v2-openapi get /activities/{index}/{source}/{id} | ||
title: Retrieve Event | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
title: 'List Events Within a Tenant' | ||
--- | ||
|
||
Browsing events within a tenant is exposed through the | ||
[/events/tenant/_search <Icon icon="code" size={16} />](#) | ||
API. | ||
|
||
This guide explains how to use the tenant feed API perform a full export | ||
of all results. | ||
|
||
## Paging | ||
|
||
The tenant feed endpoint uses parameters that match the | ||
[Flare standard paging pattern <Icon icon="book" size={16} />](/concepts/paging). | ||
|
||
## 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 **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 [/activities/:index/:source/:id <Icon icon="code" size={16} />](/api-reference/v2/endpoints/activities/get-activities) endpoint. | ||
|
||
<AccordionGroup> | ||
|
||
<Accordion title="Python SDK Example"> | ||
```python | ||
import os | ||
import time | ||
|
||
from flareio import FlareApiClient | ||
|
||
|
||
api_key: str | None = os.environ.get("FLARE_API_KEY") | ||
if not api_key: | ||
raise Exception("Please provide an API key") | ||
|
||
api_client = FlareApiClient(api_key=api_key) | ||
|
||
last_from: str | None = None | ||
fetched_pages: int = 0 | ||
|
||
for resp in api_client.scroll( | ||
method="POST", | ||
url="/firework/v4/events/tenant/_search", | ||
json={ | ||
"from": last_from, | ||
} | ||
): | ||
# Rate limiting. | ||
time.sleep(1) | ||
|
||
resp_data: dict = resp.json() | ||
|
||
fetched_pages += 1 | ||
num_results: int = len(resp_data["items"]) | ||
print(f"Fetched page {fetched_pages} with {num_results} results...") | ||
|
||
# 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters