Concepts
Pagination
Cursor paging, one page shape, everywhere.
Collections are cursor-paginated. Pass limit (max 100) and cursor:
curl -G https://api.tizon.mobile/v1/orders \
-H "Authorization: Bearer $TIZON_KEY" \
-d limit=50Every page has the same shape:
{
"object": "list",
"data": [],
"has_more": true,
"next_cursor": "crs_01J9Z8V2K5N8Q1T4W7Z0C3F6J9"
}Walk it by passing next_cursor back as cursor while has_more is true:
async function* allOrders(key) {
let cursor;
do {
const url = new URL('https://api.tizon.mobile/v1/orders');
url.searchParams.set('limit', '100');
if (cursor) url.searchParams.set('cursor', cursor);
const res = await fetch(url, { headers: { Authorization: `Bearer ${key}` } });
if (!res.ok) throw new Error(`${res.status} ${(await res.json()).error.code}`);
const page = await res.json();
yield* page.data;
cursor = page.next_cursor;
} while (cursor);
}Stop on next_cursor being null rather than on a short page. A page may come back
shorter than limit and still have more behind it.
Cursors are opaque. Do not construct, parse or store them as meaningful values — they are a position, not an id.