Skip to main content
List endpoints return results one page at a time. The One Codex API supports two pagination styles:
  • Page-based (default): request pages by number. Supported by all list endpoints.
  • Cursor-based: follow a cursor from one page to the next. Supported by /api/v1/samples, /api/v1/samples/public, and /api/v1/metadata. Recommended when fetching large numbers of samples or metadata records.

Page-based pagination

Page-based pagination follows the basic model of the GitHub API. Pages may be requested using the page and per_page query string arguments: The Link header lists links to the current (self), next, and last pages. The X-Total-Count header contains a count of the total number of items:
The next link is included on every page, including the last one. Use the last link or X-Total-Count to tell when you have reached the end.

Cursor-based pagination

To use cursor-based pagination, send the X-Pagination-Style: cursor request header. Pages are then requested using the cursor and per_page query string arguments: Each response includes an X-Next-Cursor header if more results are available. Pass its value as cursor to fetch the next page. The last page has no X-Next-Cursor header. Cursor-based responses do not include the Link or X-Total-Count headers.
The page and cursor arguments cannot be combined. Sending page with the X-Pagination-Style: cursor header, or cursor without it, returns a 400 Bad Request.
A cursor is tied to the sort order of the request that produced it. Keep the same sort and where arguments for every page.

Example

Fetch the first page of samples, most recent first:
Then pass the cursor to fetch the next page, keeping the same sort:
To fetch all samples, repeat until a response has no X-Next-Cursor header: