Skip to main content

HTTP examples

Four complete examples, one per operation, in curl, Python 3, Node 22 and Go. Every program reads the team API key from SANTATI_API_KEY; nothing else needs installing beyond requests for Python. Each one is runnable as-is. For the official clients instead, see SDKs.

1. Emit one event with an idempotency key​

POST /api/v0/events/ returns 201 when the event is created. Send an Idempotency-Key header and a retried request replays the stored event with 200 instead of writing a second one. The event's own id is also an idempotency key, scoped to the trail. See POST /api/v0/events/ and Idempotency.

status=$(curl -sS -o response.json -w '%{http_code}' \
-X POST https://api.santati.io/api/v0/events/ \
-H "Authorization: Api-Key $SANTATI_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: invoice-555-voided-1" \
-d '{"event":"invoice.voided","trail":"billing","id":"01J9Z6K3M4QX8RT2VN5B7HCWDA","created_at":"2026-09-30T14:03:11.482Z","organization_id":"acme","actor":{"type":"user","id":"usr_123"},"targets":[{"type":"invoice","id":"inv_555"}]}')

case "$status" in
201) echo "created: $(cat response.json)" ;;
200) echo "replayed: $(cat response.json)" ;;
*) echo "failed ($status): $(cat response.json)" >&2; exit 1 ;;
esac

2. Batch-emit and handle 207​

Wrap the events in {"events": [...]}, up to 500 events and 1 MiB per request. The response is 202 when every event was accepted and 207 when any were rejected; either way results carries one object per submitted index. A rejected item is {"index", "status": "rejected", "error": {"code", "message", "field"}}. See Batching and POST /api/v0/events/.

curl -sS -o batch.json -w 'HTTP %{http_code}\n' \
-X POST https://api.santati.io/api/v0/events/ \
-H "Authorization: Api-Key $SANTATI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"events":[{"event":"invoice.voided","trail":"billing","id":"01J9Z6K3M4QX8RT2VN5B7HCWDA","created_at":"2026-09-30T14:03:11.482Z","organization_id":"acme"},{"event":"invoice.paid","trail":"billing","id":"01KA1B2C3D4E5F6G7H8J9K0MNP","created_at":"2026-09-30T14:04:02.119Z","organization_id":"acme","actor":{"type":"robot","id":"bot_1"}}]}'

python3 - <<'PY'
import json

body = json.load(open("batch.json"))
print(f"accepted={body['accepted']} rejected={body['rejected']}")
for item in body["results"]:
if item["status"] == "rejected":
print(f"index {item['index']}: {item['error']['code']}")
PY

List responses carry next, previous and results, with no total count. Follow next until it is null; it is an absolute URL that already carries the cursor and every filter you sent. limit defaults to 100 and caps at 1000. See Search and GET /api/v0/events/.

url="https://api.santati.io/api/v0/events/?trail=billing&limit=100"

while [ -n "$url" ]; do
curl -sS -o page.json -H "Authorization: Api-Key $SANTATI_API_KEY" "$url"
url=$(python3 -c 'import json; print(json.load(open("page.json"))["next"] or "")')
python3 -c 'import json; [print(event["id"], event["event"]) for event in json.load(open("page.json"))["results"]]'
done

4. Handle 429 with Retry-After​

Rate-limited and over-quota requests answer 429 with the code rate_limited or quota_exceeded and a whole-second Retry-After header. Sleep for that many seconds and retry; see Rate limits.

for attempt in 1 2 3 4 5; do
status=$(curl -sS -o response.json -D headers.txt -w '%{http_code}' \
-X POST https://api.santati.io/api/v0/events/ \
-H "Authorization: Api-Key $SANTATI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"event":"invoice.voided","trail":"billing","id":"01J9Z6K3M4QX8RT2VN5B7HCWDA","created_at":"2026-09-30T14:03:11.482Z","organization_id":"acme"}')

[ "$status" != "429" ] && break
retry=$(awk 'tolower($1) == "retry-after:" {gsub("\r",""); print $2}' headers.txt)
echo "rate limited; sleeping ${retry:-1}s" >&2
sleep "${retry:-1}"
done

case "$status" in
201|200) ;;
*) echo "gave up ($status): $(cat response.json)" >&2; exit 1 ;;
esac