Before you begin
- A few documents to page through. The example assumes three.
Step 1: Read the first page
Ask for the first page, two items at a time:Request
Response
results with the items (omitted here — they are full document objects), total with the overall count, and pagination describing where you are.
That leaves two ways to move through a collection, and this response offers both. offset and limit jump straight to a page, which suits shallow access — a page of results in your own interface, for instance. Walking the whole collection is the cursor’s job: nextCursor is issued while you page from the start of the results — on the first page and then on every cursor page. Jumping in with an offset of your own leaves the walk behind, so those pages carry no cursor at all; pick one of the two approaches per traversal rather than mixing them.
A cursor is issued only for a page that came back full, which is how the walk ends: as soon as a page holds fewer items than the limit you asked for, nextCursor is null. A collection whose size is an exact multiple of the limit therefore hands you one more cursor and one final, empty page — so drive the loop off nextCursor rather than off the number of items you got.
Cursors exist only on the large collections — audit logs, documents and document search, folders and reports. On every other collection nextCursor is always null: page those with offset until a page comes back shorter than the limit.
Step 2: Follow the cursor
Pass the cursor back to get the next page:Request
Response
nextCursor is null — you have reached the end. The offset field shows your position as a progress indicator.
A cursor must be the only parameter of the request — the filters are remembered from the first page — and it expires after a period of inactivity. Continuous paging is fine; a long pause means starting over.
pagination: null instead. There is nothing to follow there, and total is the number of items you received.
Complete example
Collecting a whole collection, page by page, as a Node.js script. Error handling is minimal for brevity — in production, inspect the error envelope of non-2xx responses.Next steps
- Narrow a collection down before you page through it — Search documents.
- Handle the errors a long walk can run into, including the rate limit — Handle errors.