Guides · Guide
Pagination
How to read lists that are longer than one page.
The shape of a list
Every list endpoint returns a page and, when there is more, a cursor:
{
"data": [ { "id": "..." }, { "id": "..." } ],
"next_cursor": "eyJ0IjoiMjAyNi0xMi0wMlQwOTozMDowMCswMDowMCIsImkiOiIzZjJiOGMxZSJ9"
}next_cursor is null on the last page. Send it back as ?cursor= to get the next page, with the same filters. Treat it as an opaque string: do not decode it, build it or store it for long.
Parameters
| Parameter | Meaning |
|---|---|
limit | Items per page, 1 to 100. Default 25. |
cursor | The next_cursor of the previous page. |
A limit outside 1 to 100, or a cursor that is not one of ours, is 400 invalid_request.
Order and stability
Lists are newest first. Pages are cut at a position (the time and id of the last item), not at a count, so a page does not shift when new items arrive, and you never see an item twice or miss one because something was added while you were reading. Items created after you started will not appear in the pages you read after that point; start again to see them.
Reading everything
Never assume one page is everything. Walk the cursors until next_cursor is null. The reference clients have this built in (iterate).
let cursor
const all = []
do {
const url = new URL("https://api.colossium.cloud/v1/resources")
url.searchParams.set("limit", "100")
if (cursor) url.searchParams.set("cursor", cursor)
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.COLOSSIUM_API_TOKEN}` } })
if (!res.ok) throw new Error(String(res.status))
const page = await res.json()
all.push(...page.data)
cursor = page.next_cursor
} while (cursor)Reading everything is rarely necessary. Filter by project, service, state or kind, and keep only the fields you need. A copy of a list in your own system is a copy of data you are now responsible for.
This page as MarkdownReport a problem with this pageOlympus Group Holdings, Inc.