Skip to main content

Export events

An export writes a filtered range of your team's events to a private file you can hand to an auditor or load into another system. It is asynchronous, because the range may be large: you start a job, poll it, and download the file once it is complete. All three calls are on the API reference: Start an export, Export status and Download an export.

Exports need any team API key, including a read key, because they read events. See Authentication for scopes.

Start an export​

POST /api/v0/exports/ takes two fields:

FieldTypeMeaning
formatcsv or jsonlRequired. The file format.
querystring, urlencodedThe event list filter vocabulary: trail, event, event_prefix, organization_id, actor_id, actor_type, created_after, created_before, target_type, target_id, metadata.<key>, q and sort. Defaults to empty, which exports every event the key can read.

The request is validated like a live query before any work starts. An unknown parameter in query is a 400 naming it ({"query": {"foo": ["Not a filter this endpoint understands."]}}), never a silently narrower file, and a trail the key is not scoped to is a 403. The resolved filters and the key's trail scope are snapshotted onto the job, so editing or revoking the key later cannot change what the file contains.

curl -sS https://api.santati.io/api/v0/exports/ \
-H "Authorization: Api-Key $SANTATI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"format": "csv", "query": "trail=billing&event=invoice.voided&created_after=2026-09-01T00:00:00Z"}'
{
"id": "0192f6c2-5d19-7a64-8f0b-2e7c3d9a6b18",
"status": "pending",
"format": "csv",
"row_count": 0,
"byte_size": 0,
"created_at": "2026-09-30T14:02:11.204883Z",
"started_at": null,
"finished_at": null,
"expires_at": null,
"error": "",
"download_url": null
}

The response is 202 Accepted with the job record, which is also the status endpoint to poll. A team may have at most two exports in pending or running at once; asking for a third is a 409 (Too many exports are already running for this team.).

Poll the job​

GET /api/v0/exports/{id}/ returns the same record. status moves pending → running → complete, or ends at failed with a named error; a completed export becomes expired once its file is swept.

FieldMeaning
idThe export's id, used in the status and download URLs.
statuspending, running, complete, failed or expired.
formatcsv or jsonl.
row_countRows written. 0 until the file is complete.
byte_sizeSize of the file in bytes. 0 until the file is complete.
created_atWhen the job was accepted.
started_atWhen writing began; null while pending.
finished_atWhen the job ended, successfully or not; null while it runs.
expires_atWhen the stored file is deleted, set when the job completes; null before then.
errorEmpty on success, otherwise the failure reason — export_too_large for the row or byte ceiling, or the error message otherwise.
download_urlA freshly signed download link, or null until the file exists and while it has expired.

download_url is minted on every response and is good for one hour, so polling also refreshes the link; you never hold a URL that has already gone stale. Another team's export is a 404, not a 403.

curl -sS https://api.santati.io/api/v0/exports/0192f6c2-5d19-7a64-8f0b-2e7c3d9a6b18/ \
-H "Authorization: Api-Key $SANTATI_API_KEY"
{
"id": "0192f6c2-5d19-7a64-8f0b-2e7c3d9a6b18",
"status": "complete",
"format": "csv",
"row_count": 18422,
"byte_size": 5211884,
"created_at": "2026-09-30T14:02:11.204883Z",
"started_at": "2026-09-30T14:02:14.881902Z",
"finished_at": "2026-09-30T14:02:39.117446Z",
"expires_at": "2026-10-07T14:02:39.117446Z",
"error": "",
"download_url": "https://api.santati.io/api/v0/exports/0192f6c2-5d19-7a64-8f0b-2e7c3d9a6b18/download/?token=eyJleHBvcnRfaWQiOiIwMTkyZjZjMi01ZDE5LTdhNjQtOGYwYi0yZTdjM2Q5YTZiMTgifQ:1f2aBc:dE1n"
}

Download the file​

GET /api/v0/exports/{id}/download/?token=... streams the file as an attachment named santati-events-{id}.{format}, served as text/csv for a CSV export and application/x-ndjson for a JSONL one. The signed token is the credential, so this request takes no API key: the URL is meant to be handed to a browser or to compliance tooling. Do not log it, because it grants access to the export until it expires.

curl -sS -o santati-events-91.csv \
"https://api.santati.io/api/v0/exports/0192f6c2-5d19-7a64-8f0b-2e7c3d9a6b18/download/?token=eyJleHBvcnRfaWQiOiIwMTkyZjZjMi01ZDE5LTdhNjQtOGYwYi0yZTdjM2Q5YTZiMTgifQ:1f2aBc:dE1n"

What is in the file​

Both formats carry exactly the read shape Search events returns, so the file and the API cannot disagree: a JSONL line is one event verbatim, and a CSV row is that same event with the actor object flattened onto actor_type, actor_id, actor_name and actor_metadata. Values that are structures rather than scalars — actor_metadata, targets, metadata, data and context — become one JSON string per CSV cell.

Rows are always ordered by producer timestamp and id, newest first — the same order the list API returns. A sort=relevance in query is dropped for an export, because a file is a record of a period, not a ranked answer.

Failures and limits​

An export refuses to produce a partial file. Two ceilings end the job before or during writing, whichever is hit first:

  • more than 500,000 matching rows;
  • more than 1 GiB of output.

Either one marks the job failed with error set to export_too_large. Any other failure stores its message in error instead. Narrow the query (a trail, an event type, a time window) and start a new export.

Expiry​

A completed file is kept for seven days, after which it is deleted and the job's status becomes expired. The signed link expires much sooner — after one hour — which is why you should poll for a fresh download_url rather than storing one. Once the export has expired, no URL can retrieve it; start a new export instead.

Statuses​

StatusMeaning
200A status read, or a download.
202The export was accepted; the body is the job record.
400An unsupported format, or a query naming a parameter outside the filter vocabulary. Code invalid; fields names the offending parameter.
403The key is missing, invalid, or not scoped to a trail named in query (trail_not_allowed); or the download token is forged, expired or for another export.
404No such export for this team.
409Too many exports are already pending or running, or the file is not ready yet (export_not_ready).
410The download link or the stored file has expired (export_expired). The export must be run again.

Every error uses the shared envelope, {"error": {"code", "message", "field", "fields"}}. See Errors.

Complete walkthrough​

# 1. Start the export and keep its id.
export_id=$(curl -sS https://api.santati.io/api/v0/exports/ \
-H "Authorization: Api-Key $SANTATI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"format": "jsonl", "query": "trail=billing&event_prefix=invoice."}' \
| jq -r '.id')

# 2. Poll until it is complete, failed or expired.
while :; do
job=$(curl -sS "https://api.santati.io/api/v0/exports/${export_id}/" \
-H "Authorization: Api-Key $SANTATI_API_KEY")
status=$(echo "$job" | jq -r '.status')
echo "export ${export_id}: ${status}"
case "$status" in
complete|failed|expired) break ;;
esac
sleep 5
done

# 3. Download with the signed link from the last poll (no API key needed).
if [ "$status" = "complete" ]; then
curl -sS -o "santati-events-${export_id}.jsonl" "$(echo "$job" | jq -r '.download_url')"
else
echo "export ${export_id} ended ${status}: $(echo "$job" | jq -r '.error // "no error reported"')" >&2
exit 1
fi