Pagination
Page through any list with limit and nextCursor.
Large lists return a page of items and a cursor:
curl -s "$BASE/v1/audit?limit=50" -H "Authorization: Bearer $HERMETICA_API_KEY"
# {"items":[...],"nextCursor":"0193..."}
curl -s "$BASE/v1/audit?limit=50&cursor=0193..." -H "Authorization: Bearer $HERMETICA_API_KEY"Keep calling with cursor set to the last nextCursor. When nextCursor is null, you have everything.
let cursor = null;
do {
const url = new URL(`${BASE}/v1/events`);
url.searchParams.set('limit', '100');
if (cursor) url.searchParams.set('cursor', cursor);
const res = await fetch(url, { headers: { authorization: `Bearer ${process.env.HERMETICA_API_KEY}` } });
const page = await res.json();
for (const item of page.items) handle(item);
cursor = page.nextCursor;
} while (cursor);Small lists
Short lists, such as members, roles, reports and goals, use the same { items, nextCursor } shape and take limit and cursor too. Leave out limit and they return every item at once, with nextCursor set to null. The only list that is a plain array is the Zapier/Make trigger sample (GET /v1/hooks/triggers/<trigger>/sample), because those tools expect one.
Very large sets
For whole datasets, use an export instead of paging:
People:
POST /v1/exports {"selector":{"segmentId":"..."},"format":"csv","columns":["email","first_name"]}, then pollGET /v1/exports/<id>fordownloadUrl.Events:
POST /v1/events/export-jobs {"name":"Signed up"}.Messages:
GET /v1/messages/export(CSV).Everything:
POST /v1/account-exports {}, pollGET /v1/account-exports/<id>, then download the zip.