Sign in

Pagination

Cursors, not page numbers.

Lists take limit (1–200, default 50) and cursor. Each page ends with next; pass it back as cursor until it's null. Cursors keep their place while new items arrive, unlike page numbers.

async function* all(path) {
  let cursor = null;
  do {
    const url = new URL(`https://api.zilomail.in${path}`);
    url.searchParams.set("limit", "200");
    if (cursor) url.searchParams.set("cursor", cursor);
    const res = await fetch(url, { headers: { Authorization: `Bearer ${token}` } });
    const page = await res.json();
    yield* page.data;
    cursor = page.next;
  } while (cursor);
}

for await (const customer of all("/v1/invoice/customers")) console.log(customer.name);

Keeping a mailbox in step? Don't page through everything again: list once, then follow GET /v1/mail/changes.