Pagination
Flux API uses cursor-based pagination to efficiently handle large result sets. This approach provides consistent pagination even when data is being added or modified.
Overview
Cursor-based pagination uses opaque cursors (tokens) to navigate through pages of results. Each response includes cursors for the next and previous pages when available.
Key Benefits:
- Consistent results - No duplicate or missing records when data changes
- Performance - Efficient for large datasets
- Stateless - No server-side pagination state
Pagination Parameters
Query Parameters
- Name
limit
- Type
- integer
- Default
- default:50
- Description
Maximum number of results per page. See API Limits for allowed range.
- Name
next
- Type
- string
- Description
Cursor for getting the next page of results
- Name
previous
- Type
- string
- Description
Cursor for getting the previous page of results
Response Structure
- Name
limit
- Type
- integer
- Description
Maximum number of results per page (same as request limit)
- Name
next
- Type
- string|null
- Description
Cursor for getting next page of results.
null
if no more pages available.
- Name
previous
- Type
- string|null
- Description
Cursor for getting previous page of results.
null
if on first page.
- Name
results
- Type
- array
- Description
Array of resources for current page
Basic Pagination
First Page Request
Start pagination by making a request without any cursor parameters.
Request
curl -X POST "https://7c9h4pwu.fxns.io/api-prefix/articles/_search?limit=10" \
-H "Authorization: Simple <public_key>:<private_key>" \
-H "Content-Type: application/json" \
-d '{
"where": {
"$": {
"all_of": [
{"status__eq": "published"}
]
}
}
}'
Response
{
"limit": 50,
"next": "eyJjcmVhdGVkX2F0IjoiMjAyNC0wMS0xNVQxMDozMDowMFoiLCJfa2V5IjoiYXJ0aWNsZV8xMCJ9",
"previous": null,
"results": [
{
"_sys": {
"key": "dw2qC5qRwxuZ",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z",
"folder": "aooxoscltikj"
},
"data": {
"title": "Introduction to AI",
"status": "published"
}
},
{...}
]
}
Next Page Navigation
Getting Next Page
Use the next
cursor from the previous response to get the next page.
Request
curl -X POST "https://7c9h4pwu.fxns.io/api-prefix/articles/_search?limit=10&next=eyJjcmVhdGVkX2F0IjoiMjAyNC0wMS0xNVQxMDozMDowMFoiLCJfa2V5IjoiYXJ0aWNsZV8xMCJ9" \
-H "Authorization: Simple <public_key>:<private_key>" \
-H "Content-Type: application/json" \
-d '{
"where": {
"$": {
"all_of": [
{"status__eq": "published"}
]
}
}
}'
Second Page Response
{
"limit": 10,
"next": "eyJjcmVhdGVkX2F0IjoiMjAyNC0wMS0xNVQxMDozMDowMFoiLCJfa2V5IjoiYXJ0aWNsZV8yMCJ9",
"previous": "eyJjcmVhdGVkX2F0IjoiMjAyNC0wMS0xNVQxMDozMDowMFoiLCJfa2V5IjoiYXJ0aWNsZV8xMCJ9",
"results": [
{
"_sys": {
"key": "article_11",
"created_at": "2024-01-14T10:30:00Z",
"updated_at": "2024-01-14T10:30:00Z",
"folder": "aooxoscltikj"
},
"data": {
"title": "Next Article",
"status": "published"
}
},
{...}
]
}
Previous Page Navigation
Getting Previous Page
Use the previous
cursor to navigate backwards through pages.
Request
curl -X POST "https://7c9h4pwu.fxns.io/api-prefix/articles/_search?limit=10&previous=eyJjcmVhdGVkX2F0IjoiMjAyNC0wMS0xNVQwOTozMDowMFoiLCJfa2V5IjoiYXJ0aWNsZV8xIn0=" \
-H "Authorization: Simple <public_key>:<private_key>" \
-H "Content-Type: application/json" \
-d '{
"where": {
"$": {
"all_of": [
{"status__eq": "published"}
]
}
}
}'
Complete Pagination Example
Pagination Loop
Example showing how to iterate through all pages.
async function getAllResults(searchParams) {
let allResults = [];
let nextCursor = null;
do {
// Build URL with cursor if available
let url = 'https://7c9h4pwu.fxns.io/api-prefix/articles/_search?limit=50';
if (nextCursor) {
url += `&next=${encodeURIComponent(nextCursor)}`;
}
// Make request
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Simple ${publicKey}:${privateKey}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(searchParams)
});
const data = await response.json();
// Add results to collection
allResults = allResults.concat(data.results);
// Update cursor for next iteration
nextCursor = data.next;
console.log(`Retrieved ${data.results.length} results, total: ${allResults.length}`);
} while (nextCursor);
return allResults;
}
// Usage
const searchParams = {
where: {
$: {
all_of: [
{status__eq: "published"}
]
}
}
};
const allResults = await getAllResults(searchParams);
console.log(`Total results: ${allResults.length}`);