5 min read
Pagination
Understand how to efficiently paginate through large result sets.
How Pagination Works
All list endpoints return paginated results. Use page and per_page query parameters to control the results.
GET /v1/panels?page=1&per_page=20
{
"data": [...],
"meta": {
"page": 1,
"per_page": 20,
"total": 42,
"total_pages": 3
}
}Parameters
| Param | Type | Default | Description |
|---|---|---|---|
page | integer | 1 | Page number (1-indexed) |
per_page | integer | 20 | Items per page (max 100) |
Iterating All Pages
async function getAllPanels() {
const allPanels = [];
let page = 1;
while (true) {
const res = await fetch(
`https://api.pipesolar.com/v1/panels?page=${page}&per_page=100`,
{ headers: { "Authorization": "Bearer YOUR_KEY" } }
);
const { data, meta } = await res.json();
allPanels.push(...data);
if (page >= meta.total_pages) break;
page++;
}
return allPanels;
}