Pagination
List endpoints return paginated results. This guide explains how to navigate through large datasets efficiently.
Pagination Parameters
Section titled “Pagination Parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
page | integer | 1 | Page number (1-indexed) |
pageSize | integer | 100 | Items per page (max 1000) |
Example Request
Section titled “Example Request”curl -X GET "https://www.mando.fi/api/secure/plu?page=2&pageSize=50" \ -H "Authorization: Bearer YOUR_API_KEY"Response Headers
Section titled “Response Headers”Pagination metadata is included in response headers:
| Header | Description |
|---|---|
X-Total-Count | Total number of items |
X-Page | Current page number |
X-Page-Size | Items per page |
X-Total-Pages | Total number of pages |
Iterating Through Pages
Section titled “Iterating Through Pages”TypeScript
Section titled “TypeScript”async function getAllProducts(): Promise<Product[]> { const allProducts: Product[] = []; let page = 1; const pageSize = 100;
while (true) { const response = await client.plu.list({ page, pageSize }); allProducts.push(...response.data);
// Check if we've reached the end if (response.data.length < pageSize) { break; } page++; }
return allProducts;}Python
Section titled “Python”def get_all_products(): all_products = [] page = 1 page_size = 100
while True: response = client.plu.list(page=page, page_size=page_size) all_products.extend(response.data)
if len(response.data) < page_size: break page += 1
return all_productsCursor-Based Pagination
Section titled “Cursor-Based Pagination”Some endpoints support cursor-based pagination for better performance with large datasets:
curl -X GET "https://www.mando.fi/api/secure/sales?cursor=abc123&limit=100" \ -H "Authorization: Bearer YOUR_API_KEY"Response includes a next_cursor field:
{ "data": [...], "next_cursor": "def456", "has_more": true}Cursor Example
Section titled “Cursor Example”async function getAllSales(): Promise<Sale[]> { const allSales: Sale[] = []; let cursor: string | undefined;
while (true) { const response = await client.sales.list({ cursor, limit: 100 }); allSales.push(...response.data);
if (!response.hasMore) { break; } cursor = response.nextCursor; }
return allSales;}Filtering with Pagination
Section titled “Filtering with Pagination”Combine filters with pagination:
// Get active products, 50 per pageconst products = await client.plu.list({ page: 1, pageSize: 50, active: true, groupId: 'beverages'});Performance Tips
Section titled “Performance Tips”- Use reasonable page sizes - 100-500 items is typically optimal
- Request only needed fields - Use
fieldsparameter if supported - Cache results - Avoid re-fetching unchanged data
- Use cursors for large sets - More efficient than offset pagination
- Parallel requests - Fetch multiple pages concurrently when possible
Parallel Page Fetching
Section titled “Parallel Page Fetching”When you know the total count, fetch pages in parallel:
async function getAllProductsFast(): Promise<Product[]> { // First request to get total count const first = await client.plu.list({ page: 1, pageSize: 100 }); const totalPages = Math.ceil(first.totalCount / 100);
// Fetch remaining pages in parallel const pagePromises = []; for (let page = 2; page <= totalPages; page++) { pagePromises.push(client.plu.list({ page, pageSize: 100 })); }
const pages = await Promise.all(pagePromises); return [first.data, ...pages.map(p => p.data)].flat();}