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.
- curl
- Python
- Node
- Go
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
import os
import requests
event = {
"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"}],
}
response = requests.post(
"https://api.santati.io/api/v0/events/",
headers={
"Authorization": f"Api-Key {os.environ['SANTATI_API_KEY']}",
"Idempotency-Key": "invoice-555-voided-1",
},
json=event,
timeout=30,
)
if response.status_code not in (200, 201):
raise SystemExit(f"{response.status_code}: {response.text}")
print(f"{response.status_code}: {response.json()['id']}")
const event = {
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"}],
};
const response = await fetch("https://api.santati.io/api/v0/events/", {
method: "POST",
headers: {
Authorization: `Api-Key ${process.env.SANTATI_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "invoice-555-voided-1",
},
body: JSON.stringify(event),
});
const body = await response.json();
if (response.status !== 200 && response.status !== 201) {
throw new Error(`${response.status}: ${JSON.stringify(body)}`);
}
console.log(`${response.status}: ${body.id}`);
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
event := map[string]any{
"event": "invoice.voided",
"trail": "billing",
"id": "01J9Z6K3M4QX8RT2VN5B7HCWDA",
"created_at": "2026-09-30T14:03:11.482Z",
"organization_id": "acme",
"actor": map[string]any{"type": "user", "id": "usr_123"},
"targets": []map[string]any{{"type": "invoice", "id": "inv_555"}},
}
body, err := json.Marshal(event)
if err != nil {
panic(err)
}
req, err := http.NewRequest(http.MethodPost, "https://api.santati.io/api/v0/events/", bytes.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Api-Key "+os.Getenv("SANTATI_API_KEY"))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Idempotency-Key", "invoice-555-voided-1")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("unexpected status %s", resp.Status))
}
var stored struct {
ID string `json:"id"`
}
if err := json.NewDecoder(resp.Body).Decode(&stored); err != nil {
panic(err)
}
fmt.Println(resp.StatusCode, stored.ID)
}
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
- Python
- Node
- Go
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
import os
import requests
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"}},
]
response = requests.post(
"https://api.santati.io/api/v0/events/",
headers={"Authorization": f"Api-Key {os.environ['SANTATI_API_KEY']}"},
json={"events": events},
timeout=30,
)
if response.status_code not in (202, 207):
raise SystemExit(f"{response.status_code}: {response.text}")
body = response.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']}")
const 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"},
},
];
const response = await fetch("https://api.santati.io/api/v0/events/", {
method: "POST",
headers: {Authorization: `Api-Key ${process.env.SANTATI_API_KEY}`, "Content-Type": "application/json"},
body: JSON.stringify({events}),
});
if (response.status !== 202 && response.status !== 207) {
throw new Error(`${response.status}: ${await response.text()}`);
}
const body = await response.json();
console.log(`accepted=${body.accepted} rejected=${body.rejected}`);
for (const item of body.results) {
if (item.status === "rejected") console.log(`index ${item.index}: ${item.error.code}`);
}
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
events := []map[string]any{
{"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": map[string]any{"type": "robot", "id": "bot_1"}},
}
body, err := json.Marshal(map[string]any{"events": events})
if err != nil {
panic(err)
}
req, err := http.NewRequest(http.MethodPost, "https://api.santati.io/api/v0/events/", bytes.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Api-Key "+os.Getenv("SANTATI_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusAccepted && resp.StatusCode != http.StatusMultiStatus {
panic(fmt.Sprintf("unexpected status %s", resp.Status))
}
var batch struct {
Accepted int `json:"accepted"`
Rejected int `json:"rejected"`
Results []struct {
Index int `json:"index"`
Status string `json:"status"`
Error *struct {
Code string `json:"code"`
} `json:"error"`
} `json:"results"`
}
if err := json.NewDecoder(resp.Body).Decode(&batch); err != nil {
panic(err)
}
fmt.Printf("accepted=%d rejected=%d\n", batch.Accepted, batch.Rejected)
for _, item := range batch.Results {
if item.Status == "rejected" {
fmt.Printf("index %d: %s\n", item.Index, item.Error.Code)
}
}
}
3. Paginate with the next link
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/.
- curl
- Python
- Node
- Go
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
import os
import requests
headers = {"Authorization": f"Api-Key {os.environ['SANTATI_API_KEY']}"}
url, params = "https://api.santati.io/api/v0/events/", {"trail": "billing", "limit": 100}
while url:
response = requests.get(url, headers=headers, params=params, timeout=30)
if response.status_code != 200:
raise SystemExit(f"{response.status_code}: {response.text}")
page = response.json()
for event in page["results"]:
print(event["id"], event["event"])
# `next` is absolute and already carries the cursor and the filters.
url, params = page["next"], None
let url = "https://api.santati.io/api/v0/events/?trail=billing&limit=100";
while (url) {
const response = await fetch(url, {headers: {Authorization: `Api-Key ${process.env.SANTATI_API_KEY}`}});
if (!response.ok) {
throw new Error(`${response.status}: ${await response.text()}`);
}
const page = await response.json();
for (const event of page.results) {
console.log(event.id, event.event);
}
url = page.next;
}
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
)
func main() {
next := "https://api.santati.io/api/v0/events/?trail=billing&limit=100"
for next != "" {
req, err := http.NewRequest(http.MethodGet, next, nil)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Api-Key "+os.Getenv("SANTATI_API_KEY"))
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
if resp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("unexpected status %s", resp.Status))
}
var page struct {
Next *string `json:"next"`
Results []struct {
ID string `json:"id"`
Event string `json:"event"`
} `json:"results"`
}
if err := json.NewDecoder(resp.Body).Decode(&page); err != nil {
resp.Body.Close()
panic(err)
}
resp.Body.Close()
for _, event := range page.Results {
fmt.Println(event.ID, event.Event)
}
if page.Next == nil {
break
}
next = *page.Next
}
}
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.
- curl
- Python
- Node
- Go
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
import os
import time
import requests
event = {"event": "invoice.voided", "trail": "billing", "id": "01J9Z6K3M4QX8RT2VN5B7HCWDA",
"created_at": "2026-09-30T14:03:11.482Z", "organization_id": "acme"}
headers = {"Authorization": f"Api-Key {os.environ['SANTATI_API_KEY']}"}
for attempt in range(5):
response = requests.post("https://api.santati.io/api/v0/events/", headers=headers, json=event, timeout=30)
if response.status_code != 429:
break
delay = int(response.headers.get("Retry-After", "1"))
print(f"rate limited; sleeping {delay}s", flush=True)
time.sleep(delay)
else:
raise SystemExit("still rate limited after 5 attempts")
if response.status_code != 201:
raise SystemExit(f"{response.status_code}: {response.text}")
print(response.json()["id"])
const event = {
event: "invoice.voided",
trail: "billing",
id: "01J9Z6K3M4QX8RT2VN5B7HCWDA",
created_at: "2026-09-30T14:03:11.482Z",
organization_id: "acme",
};
const sleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));
let response;
for (let attempt = 0; attempt < 5; attempt++) {
response = await fetch("https://api.santati.io/api/v0/events/", {
method: "POST",
headers: {Authorization: `Api-Key ${process.env.SANTATI_API_KEY}`, "Content-Type": "application/json"},
body: JSON.stringify(event),
});
if (response.status !== 429) break;
const delay = Number(response.headers.get("Retry-After") ?? 1);
console.log(`rate limited; sleeping ${delay}s`);
await sleep(delay);
}
if (response.status !== 201) {
throw new Error(`${response.status}: ${await response.text()}`);
}
console.log((await response.json()).id);
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
"strconv"
"time"
)
func main() {
event := map[string]any{"event": "invoice.voided", "trail": "billing",
"id": "01J9Z6K3M4QX8RT2VN5B7HCWDA", "created_at": "2026-09-30T14:03:11.482Z",
"organization_id": "acme"}
body, err := json.Marshal(event)
if err != nil {
panic(err)
}
var resp *http.Response
for attempt := 0; attempt < 5; attempt++ {
req, err := http.NewRequest(http.MethodPost, "https://api.santati.io/api/v0/events/", bytes.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Api-Key "+os.Getenv("SANTATI_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err = http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
if resp.StatusCode != http.StatusTooManyRequests {
break
}
delay, _ := strconv.Atoi(resp.Header.Get("Retry-After"))
if delay < 1 {
delay = 1
}
resp.Body.Close()
fmt.Printf("rate limited; sleeping %ds\n", delay)
time.Sleep(time.Duration(delay) * time.Second)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusCreated {
panic(fmt.Sprintf("unexpected status %s", resp.Status))
}
var stored struct {
ID string `json:"id"`
}
if err := json.NewDecoder(resp.Body).Decode(&stored); err != nil {
panic(err)
}
fmt.Println(stored.ID)
}