Skip to main content

Overview

DocuTrust API endpoints that return lists of resources support pagination to keep response sizes manageable. The primary pagination method is cursor-based, which provides stable, performant iteration even as new records are created or deleted. Some endpoints additionally support page-based pagination for simpler random-access use cases.

Cursor-Based Pagination

Cursor-based pagination uses resource IDs as cursors. You pass an after or before parameter to fetch the next or previous page of results.

Parameters

You may pass after or before, but not both in the same request. If neither is provided, the first page of results is returned.

Response Format

Every paginated response includes a data array and a pagination object:

Pagination Object Fields

Example: Fetching the First Page

Example: Fetching the Next Page

Use the next value from the previous response as the after parameter:

Example: Fetching the Previous Page

Use the prev value from the current response as the before parameter:

Iterating Through All Results

To retrieve every record, loop until pagination.next is null.

Page-Based Pagination

Some endpoints support traditional page-based pagination as an alternative. This is useful when you need to jump to a specific page or display a page count in a UI.

Parameters

Response Format

Page-based responses include total and total_pages in the pagination object:

Page-Based Pagination Object Fields

Example Request

Page-based pagination can return inconsistent results if items are created or deleted between requests. Use cursor-based pagination when iterating through large or frequently-changing collections.

Best Practices

Cursor-based pagination is more performant and stable than page-based pagination. Results remain consistent even when records are created or deleted between page fetches. Use it as your default approach.
Set limit=100 when iterating through all records to minimize the number of API calls and stay within rate limits.
Always use the next and prev values returned by the API. Cursor values are opaque and their format may change without notice.
When pagination.next is null, there are no more records. Do not make additional requests.
When iterating through very large collections, monitor the X-RateLimit-Remaining header and add brief delays if needed. See the Errors guide for rate limit details.