Pagination
The Payonify API uses cursor-based pagination for list endpoints to allow you to iterate through large collections of resources. Our pagination implementation provides a consistent and efficient way to navigate through large result sets.
How Pagination Works
When you make a request to a list endpoint such as /v1/charges, /v1/refunds, or /v1/checkout/sessions, the API returns a paginated response that includes:
- A
dataarray containing the objects in the current page - A
pagingobject with metadata about the current page and cursors for navigating to other pages
Pagination Response Format
Code
Pagination Parameters
When querying list endpoints, below are the accepted parameters:
| Parameter | Description |
|---|---|
first | The number of objects to return per page |
after | The cursor to use as the starting point for the next page |
last | The number of objects to return per page |
before | The cursor to use as the starting point for the previous page |
Note:
firstandlastare mutually exclusive. You can only use one of them at a time.firstis used withafterandlastis used withbefore.
Example: Iterating Through Pages
First Request
Code
Response
Code
Fetching the Next Page
To get the next page, use the end_cursor from the previous response as the after parameter:
Code
Response
Code
Fetching the Previous Page
To go back to the previous page, use the start_cursor from the current response as the before parameter:
Code
Pagination Best Practices
-
Use reasonable page sizes: Keep your
limitparameter moderate (10-25) to avoid long response times. -
Check for more pages: Always check the
has_next_pagefield to determine if there are more results to fetch. -
Store cursors: When implementing pagination in your application, store both the
start_cursorandend_cursorto allow users to navigate forward and backward. -
Handle empty pages: If your request returns an empty
dataarray, it means there are no more objects to retrieve.
Iterating Through All Objects
To retrieve all objects, you can implement code similar to this (pseudocode):
Code
Notes on Cursor Stability
- Cursors are opaque tokens and their format may change without notice
- Cursors typically expire after 24 hours
- New objects added to the collection may affect pagination
Tip: You can combine pagination with filtering to efficiently navigate through specific subsets of your data. For example, you could filter charges by status and date range while using pagination to move through the results.