Pagination & Cursors
How to page through TrackMe list endpoints — opaque cursor pagination by default, the chat before variant, and admin-only offset pages.
Almost every list endpoint in the TrackMe API is cursor-paginated. You ask for a page, the server hands back the page plus an opaque meta.pagination.nextCursor, and you feed that cursor straight back to fetch the next page. You never construct, decode, or guess a cursor — it is a base64url blob that encodes the server's keyset position, and the only valid thing to do with it is echo it back verbatim.
Cursor pagination is not page-number pagination. Do not increment cursors, cache them across refreshes, build ?page=2 URLs for cursor endpoints, or stop solely on an empty items array. Read the end-to-end sequence below, then the per-style detail.
All list endpoints use the standard envelope. Pagination state lives under meta.pagination, never inside data:
{
"data": { "items": [ /* … */ ] },
"meta": { "requestId": "req_01...", "pagination": { "nextCursor": "eyJ...", "hasMore": true, "limit": 20 } }
}There are three pagination styles in the API, and you must not assume which one a given endpoint uses:
- Cursor (the default — almost all mobile lists):
?cursor=+?limit=, returnsmeta.pagination.nextCursor. beforecursor (chat message history only):?before=+?limit=, returnsmeta.pagination.nextCursor.- Offset (admin JSON API only —
/api/v1/admin/*):?page=+?limit=, returnsmeta.pagination.{page,perPage,total,lastPage}.
A handful of small lists are single-page and have no pagination object at all — see Single-page lists. Always branch on the shape of meta.pagination, not on the endpoint name.
End-to-end sequence (cursor pagination)
This is the loop for the common case — GET /api/v1/trucks/search, GET /api/v1/community/posts, and friends.
Step 1 — First request: send a limit, no cursor
Omit cursor entirely on the first page. Send limit (or accept the server default).
GET /api/v1/community/posts?limit=20 HTTP/1.1
Host: api.trackme.example
Authorization: Bearer oat_abc123...
Accept-Language: enStep 2 — Read the page and the next cursor
The page is data.items. The cursor for the next page is meta.pagination.nextCursor.
{
"data": {
"items": [
{ "id": "post_01HX...", "body": "New location today!", "createdAt": "2026-06-21T08:30:00.000Z" }
]
},
"meta": {
"requestId": "req_01HX...",
"pagination": { "nextCursor": "eyJjcmVhdGVkQXQiOiIyMDI2...", "hasMore": true, "limit": 20 }
}
}Step 3 — Next request: echo nextCursor back as cursor
Pass the exact string from meta.pagination.nextCursor as the ?cursor= query param. Keep limit the same.
GET /api/v1/community/posts?limit=20&cursor=eyJjcmVhdGVkQXQiOiIyMDI2... HTTP/1.1
Host: api.trackme.example
Authorization: Bearer oat_abc123...Step 4 — Stop when nextCursor is null
When the server has no more rows, meta.pagination.nextCursor is null (and hasMore is false). That — not an empty items array — is your terminal condition.
{
"data": { "items": [ /* last few rows */ ] },
"meta": { "requestId": "req_01HX...", "pagination": { "nextCursor": null, "hasMore": false, "limit": 20 } }
}Cursor pagination — the details
This is the default style, backed by a shared keyset helper, so the contract is identical across endpoints that use it.
Request parameters
| Param | Type | Default | Notes |
|---|---|---|---|
cursor | string (opaque) | none | Omit on the first page. On later pages, the value of the previous response's meta.pagination.nextCursor, echoed verbatim. |
limit | integer | endpoint-specific (commonly 20) | Page size. Each endpoint clamps to its own max (e.g. community posts cap at 50). |
Response meta.pagination shape
| Field | Type | Meaning |
|---|---|---|
nextCursor | string | null | Pass back as ?cursor= to get the next page. null means you've reached the end. |
hasMore | boolean | true if another page exists. Equivalent to nextCursor !== null. |
limit | integer | The page size that was applied (the server's clamped value, which may be lower than what you asked for). |
What a cursor actually is (and why you must not parse it)
A cursor is a base64url-encoded JSON object describing the server's position in a deterministic ORDER BY — for a plain chronological list that's { id }; for ranked lists (geo + featured + rating) it carries the extra ranking fields. The encoding is an implementation detail and can change without notice. Treat it as an opaque token: store it if you must, echo it back, but never decode it, mutate it, or hand-craft one. A malformed cursor is rejected.
A cursor is not a page number. Do not do arithmetic on it, do not persist it as a durable bookmark across app restarts (the underlying rows may have shifted), and do not try to "jump" to page N. Cursor pagination is forward-only sequential paging. If you need random page access or a total count, that capability does not exist on these endpoints — only the admin offset endpoints expose total/lastPage.
Endpoints using cursor pagination
These return meta.pagination.{ nextCursor, hasMore, limit }:
GET /api/v1/trucks/search— public truck discovery (cursor+limit, default20). The cursor encodes ranking when a geo query is in play.GET /api/v1/community/posts— community feed (cursor+limit,1–50, default20).GET /api/v1/community/posts/:id/replies— replies on a post (cursor+limit,1–50, default20).
See Discovery & search and Community for the per-feature field details.
The before variant — chat message history
Chat message history pages backwards in time and uses before instead of cursor. The intent is "give me the messages older than the one I currently have at the top of the list."
GET /api/v1/chats/conv_01HX.../messages?limit=50&before=msg_01HX... HTTP/1.1
Host: api.trackme.example
Authorization: Bearer oat_abc123...{
"data": { "items": [ /* messages, newest first */ ] },
"meta": { "requestId": "req_01HX...", "pagination": { "nextCursor": "msg_01HW...", "limit": 50 } }
}| Param | Type | Default | Notes |
|---|---|---|---|
before | string | none | A message id. Returns messages older than it. Omit for the most recent page. |
limit | integer | 50 | 1–100. |
Differences from the default style to watch for:
- The request param is
before, notcursor. - The response
meta.paginationhasnextCursorandlimitonly — there is nohasMorefield here. Stop whennextCursorisnull. - To page further back, pass the returned
nextCursoras the nextbefore.
Full chat flow: Chat & realtime.
Offset pagination — admin JSON API only
The admin endpoints under /api/v1/admin/* use classic offset paging because operators frequently scan deep into heavy tables and need a total count and the ability to jump to a page. No mobile-app endpoint uses this style — if you are building the customer or owner app, you will never hit it.
GET /api/v1/admin/orders?page=2&limit=50&status=completed HTTP/1.1
Host: api.trackme.example
Authorization: Bearer oat_admin...{
"data": { "items": [ /* … */ ] },
"meta": {
"requestId": "req_01HX...",
"pagination": { "page": 2, "perPage": 50, "total": 1840, "lastPage": 37 }
}
}| Param | Type | Default | Notes |
|---|---|---|---|
page | integer | 1 | 1-based page index. |
limit | integer | 50 | Page size, max 100. |
| Response field | Type | Meaning |
|---|---|---|
page | integer | The page returned. |
perPage | integer | The applied page size. |
total | integer | Total matching rows across all pages. |
lastPage | integer | The highest valid page value. |
Increment page until page === lastPage. Note these field names (perPage, lastPage) differ from the cursor style — do not write one parser and point it at both.
Single-page lists
A few lists are intentionally capped to a single response and carry no pagination object at all. Do not loop on these — there is no nextCursor to follow. Read every row from data.items once.
| Endpoint | Cap | Notes |
|---|---|---|
GET /api/v1/notifications | limit (default 50) | Returns one page; meta carries unreadCount, no pagination. Backstops the SSE/FCM push feed on app open / pull-to-refresh. |
GET /api/v1/chats | n/a | The conversation inbox returns all of the caller's conversations in one shot — no cursor, no pagination. (Message history within a chat uses the before variant above.) |
GET /api/v1/jobs | limit (default 20) | Public job discovery returns a single page of live listings; no pagination object. |
The signal for "is this list paginated?" is the presence of meta.pagination. If it is absent, you have the whole list. If it is present, page until the style's terminal condition (nextCursor === null for cursor/before, page === lastPage for offset).
State / transitions reference
A pagination loop is a tiny state machine. Drive it off the response, never off a counter you maintain.
| State | Meaning | How you got here | What's allowed next |
|---|---|---|---|
initial | No request sent yet | App opened the list / pull-to-refresh | Send page 1: omit cursor/before/page (or page=1), send limit. |
has-next | A page returned with a non-null cursor (or page < lastPage) | Server had more rows than limit | Echo nextCursor → cursor/before, or page + 1. Append items to the list. |
exhausted | Last page returned | nextCursor === null (cursor/before) or page === lastPage (offset) | Stop. Re-enter initial only on a fresh refresh. |
single-page | Endpoint has no pagination object | Called a single-page list (notifications, chats inbox, jobs) | Render all items; do not loop. |
Transitions:
initial → has-next— first page came back withhasMore: true/nextCursorset /page < lastPage.initial → exhausted— first page already hadnextCursor: null/page === lastPage(the list fit in one page).has-next → has-next— keep paging; each response either keeps the cursor flowing or flips you toexhausted.has-next → exhausted— the server returnednextCursor: null(or you reachedlastPage).* → initial— user pull-to-refreshes; discard the old cursor and start clean from page 1.
Implementation Notes
- Stopping on empty
items. A cursor page can occasionally come back short whilenextCursoris still non-null. Stop onnextCursor === null/hasMore === false, never onitems.length. - Mutating or constructing a cursor. Cursors are opaque base64url tokens. Hand-rolling
?page=2against a cursor endpoint, or appending to the cursor string, produces anInvalid cursorerror or wrong results. - Re-using a stale cursor after refresh. On pull-to-refresh, drop the cursor and re-request page 1. Cursors point at row positions that may have shifted.
- Sharing one parser across styles. Cursor →
{ nextCursor, hasMore, limit }. Chat →{ nextCursor, limit }. Offset →{ page, perPage, total, lastPage }. Branch on which keys are present. - Assuming a
total. Cursor andbeforeendpoints deliberately omit a total count — there is no "X of Y" without paging to the end. Only the admin offset endpoints exposetotal/lastPage.
See the API reference for the exact query parameters and response schema of each list endpoint.