Pagination
Handling paginated results in the Bluerails API using cursor-based pagination.
Most “list” endpoints in the Bluerails API (like listing accounts, payments, or payouts) return results in chunks, or “pages,” rather than all at once. This prevents overly large responses and allows you to fetch data incrementally. We use cursor-based pagination.
How Cursor Pagination Works
Instead of traditional page numbers, cursor pagination uses an opaque cursor
string that points to a specific item in the dataset. To get the next page of results, you provide the cursor
received from the previous response.
Query Parameters:
You control pagination using these query parameters on list endpoints:
limit
(optional, integer):- Specifies the maximum number of items to return per page.
- Default:
25
- Maximum:
100
cursor
(optional, string):- The cursor string obtained from the
next_cursor
field of the previous page’s response. - Omit this parameter entirely for the very first request to get the beginning of the list.
Response Body:
Paginated list endpoints return a JSON object with the following structure:
Example Workflow: Listing Accounts
-
Initial Request (Get the first page)
- Omit the
cursor
parameter. - (See diagram: “Initial Request”)
- Omit the
-
Server Response (First Page)
- The server returns the first 50 accounts and a
next_cursor
. - (See diagram: “Server Response (Data + next_cursor=“abc”)”)
- The server returns the first 50 accounts and a
-
Next Request (Get the second page)
- Use the
next_cursor
value from the previous response as thecursor
query parameter. - (See diagram: “Next Request (cursor=“abc”, limit=50)”)
- Use the
-
Server Response (Second Page)
- The server returns the next 50 accounts and a new
next_cursor
. - (See diagram: “Server Response (Data + next_cursor=“xyz”)”)
- The server returns the next 50 accounts and a new
-
Repeat
- Continue making requests, using the latest
next_cursor
value each time. - (See diagram: “Repeat using latest next_cursor…”)
- Continue making requests, using the latest
-
Final Page
- Eventually, a response will have
next_cursor
asnull
or omitted, indicating there are no more pages. - (See diagram: “Final Response (Data + next_cursor=null)”)
- Eventually, a response will have