Pagination
Fusion supports pagination to manage the retrieval of large datasets efficiently. By default, Fusion returns a limited number of records per request. The fetch and offset parameters allow you to control the number of records retrieved and navigate through the dataset.
Table of contents
- Default Behavior
fetchParameteroffsetParameter- Pagination Strategy
- Handling Empty Results
- Combining
fetch,offset, andquery - Best Practices
- Limitations
- Example Scenario
- Troubleshooting
Default Behavior
- Default
fetchValue: If not specified, Fusion returns 10 records per request. - Default
offsetValue: If not specified, Fusion starts from the first record (offset0).
fetch Parameter
Specifies the maximum number of records to return in a single response. To adjust the number of records returned, include the fetch parameter in your request URL. If fetch is less than 1 or not a valid number, it defaults to 10, while if fetch exceeds 100, it is set to 100.
Examples
-
Retrieve 5 Records:
GET https://fusion.globetrotter.com.au/api/v1/invoices?fetch=5Returns a maximum of 5 records.
-
Attempt to Retrieve More Than 100 Records:
GET https://fusion.globetrotter.com.au/api/v1/invoices?fetch=150Since
fetchexceeds the maximum allowed value, it will be capped at 100.
offset Parameter
Specifies the number of records to skip before starting to return records. Use the offset parameter to retrieve subsequent pages of results.
Examples
-
Skip the First 20 Records:
GET https://fusion.globetrotter.com.au/api/v1/bookings?offset=20Starts returning records from the 21st record onward.
-
Retrieve Records in Batches of 50:
GET https://fusion.globetrotter.com.au/api/v1/itineraries?offset=0&fetch=50Retrieves records 1 to 50.
GET https://fusion.globetrotter.com.au/api/v1/itineraries?offset=50&fetch=50Retrieves records 51 to 100.
Pagination Strategy
To retrieve all records in a dataset larger than 100 records, increment the offset by the fetch value in each subsequent request.
Example:
Retrieve all invoices in batches of 100 records:
-
First Request (records 1–100):
GET https://fusion.globetrotter.com.au/api/v1/invoices?offset=0&fetch=100 -
Second Request (records 101–200):
GET https://fusion.globetrotter.com.au/api/v1/invoices?offset=100&fetch=100 -
Third Request (records 201–300):
GET https://fusion.globetrotter.com.au/api/v1/invoices?offset=200&fetch=100 -
Continue Incrementing
offset:Increase the
offsetby100each time until Fusion returns an emptyresultarray.
Handling Empty Results
When there are no more records to retrieve, Fusion returns an empty array in the result field:
{
"result": []
}
This indicates that all records have been retrieved, and you can stop making further requests.
🛈 An empty
resultarray means there are no records matching the currentqueryandoffset. 🛈 When usingoffsetwith aquery, theoffsetapplies to the filtered results. 🛈 Refer to the endpoint documentation to find out the ordering key.
Combining fetch, offset, and query
You can combine pagination parameters with queries to retrieve filtered data in manageable chunks.
Example:
Retrieve all bookings for ClientNumber 12345 in batches of 50 records:
-
First Request (records 1–50):
GET https://fusion.globetrotter.com.au/api/v1/bookings?query=ClientNumber^EQ12345&offset=0&fetch=50 -
Second Request (records 51–100):
GET https://fusion.globetrotter.com.au/api/v1/bookings?query=ClientNumber^EQ12345&offset=50&fetch=50 -
Continue Incrementing
offset:Increase the
offsetby50each time until you receive an emptyresultarray.
Important:
🛈 The
offsetapplies **after the query filters the records.** 🛈 Ensure youroffsetandfetchvalues are consistent across requests for accurate pagination.
Best Practices
- Monitor for Empty Results:
- Use the empty
resultarray to determine when to stop paginating.
- Use the empty
- Consistent
fetchSize:- Keep the
fetchsize consistent to simplify pagination logic.
- Keep the
- Avoid Large
offsetValues:- Large
offsetvalues may lead to performance issues. - Consider refining your query to reduce the dataset size.
- Large
Limitations
🛈 There is no explicit maximum
offset, but extremely high values might result in performance degradation or timeouts.
Rate Limiting:
⚠ Fusion may rate-limit requests that exceed safe thresholds. Systems should be designed to back-off and retry if rate limiting occurs.
Example Scenario
Goal: Retrieve all itineraries starting from September 1, 2023, for ClientNumber 12345.
Steps:
-
Define the Query:
query=ClientNumber^EQ12345;BookingDate^GE2023-09-01 -
Initialize Pagination Parameters:
offset:0fetch:100
-
First Request:
GET https://fusion.globetrotter.com.au/api/v1/itineraries?query=ClientNumber^EQ12345;BookingDate^GE2023-09-01&offset=0&fetch=100 -
Subsequent Requests:
- Increment
offsetby100with each request. - Continue until an empty
resultarray is received.
- Increment
Code Snippet (pseudo-code):
offset = 0
fetch = 100
do {
response = GET /itineraries?query=...&offset=offset&fetch=fetch
process(response.result)
offset += fetch
} while (response.result is not empty)
Troubleshooting
- Empty
resultBefore Expected:- Verify that your query parameters are correct.
- Ensure that the
offsethas not exceeded the number of available records.
- Duplicate or Missing Records:
- Confirm that the default ordering has not changed between requests.
- Ensure that
offsetincrements match thefetchsize.
- Performance Issues:
- Reduce the
fetchsize if experiencing timeouts. - Optimize your query to narrow down the results.
- Reduce the