Guides
Pagination
Walk through lists with cursor-based pagination.
List endpoints return the most recent items first and use cursor-based pagination: you pass the id of the last item you received and ask for the page that follows.
| Parameter | Description |
|---|---|
limit | Items per page, from 1 to 100 (default 20). |
starting_after | The id of the last item of the previous page. |
Every list response has the same shape:
{
"object": "list",
"data": [ { "id": "4821", "object": "user" } ],
"has_more": true
}When has_more is true, call again with starting_after set to the id of the last element of data. Stop when has_more is false.
async function* allUsers() {
let startingAfter
do {
const url = new URL('https://sdk.tilt-pay.com/v1/users')
url.searchParams.set('limit', '100')
if (startingAfter) url.searchParams.set('starting_after', startingAfter)
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.TILT_PAY_API_KEY}` } })
const page = await res.json()
yield* page.data
startingAfter = page.has_more ? page.data.at(-1).id : undefined
} while (startingAfter)
}
for await (const user of allUsers()) console.log(user.id)Good to know#
- Identifiers are opaque strings. Do not parse them or assume they are sortable: always use the
idas it was returned. - An unknown cursor, or one that belongs to another project or environment, returns
400 invalid_cursor. - New items can appear while you paginate. They are created at the front of the list, so they never shift the pages you have not read yet.
- List the effective fees is not paginated and always returns
has_more: false.