Pagination
Pagination
SagaPay APIs provides page-based pagination, enabling efficient and controlled data retrieval. This is essential in scenarios where the API returns lists of data. Our APIs adheres to the following principles in all such scenarios:
- The list is always sorted from newer to older based on time of creation.
- Page size is always maintained at 100.
- The total number of items is available as a header in the response without affecting the API structure.
Using Pagination
To retrieve a specific page, include the desired page number as a page parameter in the request header. By default, the APIs return the first page if no page parameter is specified.
The response headers will indicate the total number of entries. If a non-existent page is requested, you will receive an empty array with status SUCCESS and a message.
Example Request with Page Number
Response Headers and Body
The response headers and the body for a successful response:
Empty Page Response
For cases where the page number exceeds the total available pages, the response structure would be:
Calculating Total Pages
To calculate the total number of pages, use the following formula:
For example, if x-total-items is 230 and page size is 100:
Pagination Workflow
Best Practices
Always start by requesting page 1 to get the total item count from x-total-items.
Use the total items to calculate how many pages exist before iterating.
Always handle the case where the requested page returns an empty array.
Make sequential requests to avoid rate limiting issues.