Pagination

Page through any list with limit and nextCursor.

Embed
Preview of the card
<a href="https://hermeticor.com/guides/pagination"><img src="https://hermeticor.com/guides/_api/public/orgs/5fcd8b3c-a27c-4688-972f-de710125592f/spaces/9a3da731-ded5-4536-b84f-8c9a61420ff4/pages/9716676d-f98d-4f63-add4-2c747fe2e5da/social-card.svg?v=3e7ae33eec8b" alt="Pagination" width="600" height="315"></a>

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 poll GET /v1/exports/<id> for downloadUrl.

  • Events: POST /v1/events/export-jobs {"name":"Signed up"}.

  • Messages: GET /v1/messages/export (CSV).

  • Everything: POST /v1/account-exports {}, poll GET /v1/account-exports/<id>, then download the zip.

Updated