Pagination
Learn how to paginate through large result sets.
Overview
List endpoints that return multiple items support pagination using query parameters. This helps you efficiently work with large datasets by breaking them into smaller pages.
Query Parameters
per_pageintegerNumber of results to return per page. Accepts values from 1 to 100. Defaults to 10.
pageintegerPage number to retrieve (minimum 1). Defaults to 1.
sort_bystringField to sort results by. Supported fields vary by endpoint:
- Customers & Vendors: "created_at", "name", "updated_at"
- Donation Intents: "created_at" only
Defaults to "created_at".
sort_orderstringSort direction: "asc" for ascending or "desc" for descending. Defaults to "desc".
Response Format
Paginated responses include metadata to help you navigate through pages:
{
"data": [
// ... array of results
],
"current_page": 1,
"from": 1,
"to": 10,
"per_page": 10,
"last_page": 10,
"total": 100
}current_page: The current page numberfrom: Index of the first item on this pageto: Index of the last item on this pageper_page: Number of items per pagelast_page: Total number of pagestotal: Total number of items across all pagesExamples
GET https://testing.impactapi.co/donation_intents?per_page=20&page=1
GET https://testing.impactapi.co/donation_intents?per_page=20&page=2
GET https://testing.impactapi.co/donation_intents?per_page=20&page=1&sort_by=created_at&sort_order=asc
Best Practices
- Use reasonable page sizes (10-50 items) for better performance
- Check
last_pageto determine if more pages are available - Cache results when appropriate to reduce API calls
- Consider the
totalcount when displaying pagination UI - Use
fromandtoto show users their position in the results
Implementation Example
async function getAllDonationIntents() {
const allIntents = [];
let page = 1;
let hasMore = true;
while (hasMore) {
const response = await fetch(
`https://testing.impactapi.co/donation_intents?per_page=50&page=${page}`,
{
headers: {
'Authorization': `Bearer ${process.env.IMPACT_API_KEY}`
}
}
);
const result = await response.json();
allIntents.push(...result.data);
hasMore = page < result.last_page;
page++;
}
return allIntents;
}Best Practices
When requesting a page number beyond last_page, the API returns a 200 status with an empty data array. The pagination metadata will still be included with accurate values.
// Requesting page 999 when only 10 pages exist
{
"data": [],
"current_page": 999,
"from": null,
"to": null,
"per_page": 10,
"last_page": 10,
"total": 100
}Always check last_page before making requests to avoid unnecessary API calls.