Pagination
Page through Kustomer list endpoints with page and pageSize, follow links.next, and handle cursor-based and very large result sets.
List endpoints return results a page at a time. Most use page numbers; a few use cursors. Either way, the safest approach is to follow links.next until it's null.
Page-number pagination
Pass page (starting at 1) and pageSize:
curl "https://acme.api.kustomerapp.com/v1/customers?page=2&pageSize=100" \
-H "Authorization: Bearer $KUSTOMER_API_KEY"{
"meta": { "pageSize": 100, "page": 2, "total": 4210, "totalPages": 43 },
"links": {
"self": "/v1/customers?page=2&pageSize=100",
"first": "/v1/customers?page=1&pageSize=100",
"prev": "/v1/customers?page=1&pageSize=100",
"next": "/v1/customers?page=3&pageSize=100"
},
"data": [ ... ]
}No response yet. Send the first request, or press play.
300 pages · only pages 1–100 (10,000 records) can be fetched; asking for page 101 returns 400. Split the query into at least 3 windows on updated_at and page through each.
Page sizes
pageSize limits vary by endpoint. The reference page for each list shows its default and maximum.
Request the largest page size you can handle. Fewer, larger pages use less of your rate limit.
Iterate every page
async function* listAll(path: string) {
let next: string | null = `${path}${path.includes('?') ? '&' : '?'}pageSize=100`
while (next) {
const res = await kfetch(next) // retries 429s; see Making requests
const body = await res.json()
yield* body.data
next = body.links?.next ?? null
}
}
for await (const customer of listAll('/v1/customers')) {
console.log(customer.id, customer.attributes.name)
}links.next is a path. Prefix it with your base URL.
Cursor pagination
A few endpoints, such as the audit log, page with before and after cursors instead. Their links.next already contains the cursor:
{ "links": { "next": "/v1/audit-logs?count=1&before=62799c44a96e7f160834199c" } }The same "follow links.next" loop works without changes.
Large result sets
Deep pagination gets slower and can hit limits. For exports and syncs:
- Customer list and search return only the first 10,000 matches.
GET /v1/customers,POST /v1/customers/searchandPOST /v1/customers/archive/searchshare a 10,000-match window. The last reachable page isfloor(10,000 / pageSize), and never above 999. A higherpagereturns400with abadparamerror onpage. On the last reachable page,links.nextisnullandlinks.lastpoints there;meta.totalPagescan still be higher when more matches exist. WhenpageSizedoes not divide 10,000, or the 999-page cap binds first, matches inside the window can be left unread (for examplepageSize=333stops at page 30 / 9,990 matches, andpageSize=5stops at page 999 / 4,995) — comparemeta.totalPageswith the pages you read. If pages remain unread and the query matches 10,000 or fewer, restart frompage=1with apageSizethat divides 10,000 (such as 100, 250 or 500). If the query matches more than 10,000, restarting only re-reads the same window — split into smaller windows instead. Do not continue at the next page number after changingpageSize— page offsets depend onpageSize, so that can duplicate or skip matches. SearchpageSizegoes up to 500 (a larger value is treated as 500); the customer list goes up to 1,000. Search also acceptspageSize=0for counts only, which doesn't apply the window. Split large queries into time windows onupdated_atorcreated_at, and page through each window. See Search recipes. - Sort for stability. Records created or updated while you page can shift between pages. Window by time, or sort by a stable field where the endpoint supports it. The customer list adds an id tie-break so equal sort values stay in a consistent order across pages.
- Incremental sync. After the first full pass, query only records updated since your last run instead of re-listing everything.
- Subscribe instead of polling. If you poll for changes, consider outbound webhooks.