Pagination
Cursor paging, the four pagination modes, sorting, filters and the pitfalls that stop an iteration early.
Paging is per endpoint, and every list endpoint tells you which kind it uses. Read
x-pagination on the operation in the OpenAPI document (shown on every
API Reference page) rather than guessing from whether a cursor
parameter happens to be present.
"x-pagination": { "mode": "cursor" }mode | What it means | What to do |
|---|---|---|
cursor | Cursor-paginated with a default page size. | Iterate until meta.next_cursor is null. |
cursor-optional | Returns the whole collection unless you send limit. | Send limit if you want pages; otherwise expect one page and next_cursor: null. |
offset | limit + offset. Used only where relevance ordering leaves no stable sort key. | Increment offset by limit. |
none | Not paginated. Carries a reason and a bound saying why and how large it can get. | Read the whole response. |
The distinction you most need is cursor versus cursor-optional. Both advertise a
cursor parameter, but only cursor will ever hand a non-null next_cursor to a caller
who did not ask for paging.
Cursor pagination
GET /v1/<resource>?limit=<n>&cursor=<opaque>&sort=<field>| Param | Required | Default | Max |
|---|---|---|---|
limit | no | per endpoint | per endpoint |
cursor | no — omit on the first page | — | — |
sort | no — per-resource default | — | — |
limit bounds are per endpoint. Most are 1..100, default 50; others allow up to 200
or 500, with a default of 50 or 200. The operation's limit description is authoritative,
and meta.limit reports the size actually used.
Response meta carries the pagination keys directly:
{
"request_id": "…",
"api_version": "2026-04-23",
"next_cursor": "eyJ2IjoxLCJ2YWxzIjpbI…",
"limit": 50
}next_cursor is null on the last page and always present on a paginated response, so
while (meta.next_cursor) is the correct loop.
How to iterate
async function* allPages(path: string, headers: HeadersInit) {
let cursor: string | null = null;
do {
const url = new URL(path, 'https://api.acreum.io');
url.searchParams.set('limit', '100');
if (cursor) url.searchParams.set('cursor', cursor);
const res = await fetch(url, { headers });
if (!res.ok) throw await res.json();
const { data, meta } = await res.json();
yield data;
cursor = meta.next_cursor ?? null;
} while (cursor);
}Iterate until next_cursor is null. Do not stop on data.length < limit: a page may
legitimately come back short.
Cursors are opaque
cursor is a base64url-encoded string. Do not parse it. Its contents can change
without notice, and such a change is not a breaking API change. The only valid operations
on a cursor are: pass it back unchanged, discard it and start over, or compare it for
equality.
Sort
Each cursor-paginated endpoint declares an allowlist of sort fields; the default is
documented per resource (typically -created_at).
GET /v1/documents?sort=document_date
GET /v1/documents?sort=-document_date # leading "-" reverses the directionA cursor holds the sort values of the last row on the page, not the sort or filters that
produced it, and the server does not check that they still match. Keep sort and every
filter unchanged while you pass a cursor back; to change them, start over without a cursor.
A cursor reused under a different sort is not refused, it silently returns the wrong page.
Offset pagination
GET /v1/search declares x-pagination: { "mode": "offset" } and takes limit +
offset. Search results are ordered by relevance, which gives no stable key to encode in a
cursor.
Unpaginated endpoints
An endpoint declaring x-pagination: { "mode": "none", … } returns its whole collection.
The declaration's reason says why ("org configuration, created by an administrator") and
bound says what limits the size. These are genuinely bounded collections: status
vocabularies, ticket categories, an organization's legal entities.
Filters
Filtering is typed per resource; there is no generic filter language. Date ranges use
from_date / to_date. A few endpoints still accept an older spelling (from/to,
entry_date_from/entry_date_to); those are marked deprecated and will be removed in a
future major version. as_of_date is a point-in-time filter used by reporting endpoints,
not a range bound.
Filters compose with pagination: a cursor is a position within the filtered, sorted result set. Changing a filter mid-iteration gives undefined results; start over instead.
Limit
limit=0, negative or non-numeric values return400 VALIDATION_FAILED. A decimal is truncated (2.5reads as2).- A
limitabove the endpoint's maximum is clamped, not rejected.meta.limitreports what was used. - Omitting
limitgives the default on acursorendpoint and the entire collection on acursor-optionalone.
Stability under concurrent writes
A cursor is positionally stable. Records inserted after your current position (in sort
order) appear on later pages; records inserted before it will not appear in this
iteration; a record deleted mid-iteration is simply absent. For a point-in-time snapshot,
capture a timestamp at the start and filter to_date against it.
Invalid cursors
{
"type": "https://docs.acreum.io/errors/INVALID_CURSOR",
"title": "Invalid cursor",
"status": 400,
"detail": "The supplied pagination cursor could not be decoded. Omit the cursor to start from the first page.",
"code": "INVALID_CURSOR",
"request_id": "…",
"instance": "/v1/documents"
}The server refuses a cursor it cannot decode, or one written in an older internal cursor format. Causes, in order of likelihood: the cursor was decoded and re-encoded by the client; it was URL-encoded twice; it was truncated. In every case, drop the cursor and restart from page one.
Counts
List endpoints do not return total counts. For a bounded collection (mode: none), count
client-side. For analytics, use the relevant /v1/reports/* endpoint. For "is there more
than one page", next_cursor !== null is enough.
Pitfalls
- Assuming every list paginates. Check
x-pagination. - Assuming
limitmaxes at 100. It is per endpoint. - Treating
data.length < limitas end-of-list. Onlynext_cursor === nullmeans that. - Double-encoding the cursor. It is already URL-safe.
- Switching
sortor a filter with a stale cursor. It is not refused; it returns the wrong page. Start over. - Persisting cursors. A cursor is good for roughly one iteration, not forever.