Pagination
Endpoints that return collections of resources use cursor-free, offset-based pagination. This page explains the query parameters, response format, and best practices for efficiently paginating through result sets.
Query Parameters
All paginated endpoints accept the following query parameters:
Pagination Parameters
Example Request
Fetch the second page of transfers, 10 per page, sorted by creation date descending:
curl -X GET "https://api.elaypay.app/api/v1/transfer/query/orders?page=1&size=10&sort=createdAt,desc" \
-H "X-Api-Key: sk_live_abc123def456" \
-H "X-Signature: <computed-signature>" \
-H "X-Timestamp: 1709337600" \
-H "X-Nonce: 550e8400-e29b-41d4-a716-446655440000"
Pages are zero-indexed. page=0 returns the first page, page=1 returns the second page, and so on.
Response Format
Paginated responses wrap the result list in a data object that includes total count, page metadata, and navigation information.
Response Fields
| Field | Type | Description |
|---|---|---|
data.content | array | The list of items for the current page. |
data.page.size | integer | The requested page size. |
data.page.number | integer | The current page number (zero-based). |
data.page.totalElements | integer | Total number of items across all pages. |
data.page.totalPages | integer | Total number of pages. Computed as ceil(totalElements / size). |
Sort Expressions
The sort parameter accepts a field name and a direction, separated by a comma:
sort=field,direction
| Direction | Meaning |
|---|---|
asc | Ascending order (A-Z, oldest first, smallest first) |
desc | Descending order (Z-A, newest first, largest first) |
Examples
| Expression | Behavior |
|---|---|
sort=createdAt,desc | Newest items first |
sort=amount,asc | Smallest amounts first |
sort=status,asc | Alphabetical by status |
Multiple Sort Fields
To sort by multiple fields, repeat the sort parameter. The first field is the primary sort; subsequent fields break ties:
?sort=status,asc&sort=createdAt,desc
This sorts by status alphabetically, then by creation date (newest first) within each status group.
Not all fields are sortable. Attempting to sort by a non-sortable field returns S012 (INVALID_PARAMETER). Common sortable fields include createdAt, updatedAt, amount, and status. Refer to the specific endpoint documentation for the list of supported sort fields.
Limits and Defaults
| Parameter | Default | Minimum | Maximum |
|---|---|---|---|
page | 0 | 0 | No upper limit (but pages beyond totalPages return empty content) |
size | 20 | 1 | 100 |
If you request a size greater than 100, the server will cap it at 100 without returning an error. If you request a negative page or size, the server returns S012 (INVALID_PARAMETER).
Iterating Through All Pages
Here is a JavaScript example that fetches all pages of a paginated endpoint:
async function fetchAllPages(path, apiKey, apiSecret) {
const allItems = [];
let page = 0;
let totalPages = 1; // Will be updated after the first request
while (page < totalPages) {
const response = await apiRequest(
'GET',
`${path}?page=${page}&size=100&sort=createdAt,desc`,
null,
apiKey,
apiSecret
);
if (!response.success) {
throw new Error(`API error: ${response.code} - ${response.message}`);
}
allItems.push(...response.data.content);
totalPages = response.data.page.totalPages;
page++;
}
return allItems;
}
// Usage
const allTransfers = await fetchAllPages(
'/api/v1/transfer/query/orders',
'sk_live_abc123def456',
'your-api-secret-here'
);
Fetching all pages in a loop works well for small to medium datasets. For very large datasets (thousands of items), consider whether you truly need all records at once. Often, you can filter by date range or status to reduce the result set, or process items page by page without accumulating them all in memory.
Empty Results
When a page has no items (either because the collection is empty or you requested a page beyond the last), the response returns an empty content array with accurate metadata:
Tips for Efficient Pagination
Most list endpoints support query filters (by status, date range, ID prefix, etc.) in addition to pagination. Apply filters to narrow results before paginating, rather than fetching everything and filtering client-side.
The default size of 20 is suitable for UI-driven pagination. For batch processing or data export, use size=100 to minimize the number of HTTP round-trips. For mobile clients or low-bandwidth scenarios, consider a smaller size like 10.
In highly active systems, items may be created or deleted between page requests. This can cause items to shift between pages (appearing twice or being skipped). If exact-once processing is critical, use date-range filters with a fixed timestamp boundary instead of relying on page numbers alone.
The totalElements and totalPages values are computed on every request. If you are building a UI with page numbers and the total count does not change frequently, cache these values after the first request rather than re-reading them on every page navigation.