Overview
All Smartbills API list endpoints support pagination to help you efficiently retrieve large datasets. We use cursor-based pagination for optimal performance and consistency.Cursor-based pagination: Smartbills uses cursor-based pagination rather than offset-based pagination for better performance and reliability with large datasets.
How Pagination Works
Request Parameters
All list endpoints accept these pagination parameters:integer
default:"1"
Page number to retrieve (starts at 1)
integer
default:"20"
Number of items per page
- Minimum: 1
- Maximum: 100
- Default: 20
Response Format
Paginated responses include both data and pagination metadata:Pagination Object
object
Pagination metadata
Basic Examples
First Page
Retrieve the first page of results:Next Page
Navigate to the next page:Iterating Through All Pages
Simple Iteration
Loop through all pages to retrieve all results:With Error Handling
Production-ready pagination with error handling:Best Practices
Use Appropriate Page Sizes
Use Appropriate Page Sizes
Choose the right page size for your use case:
- Small pages (20-50): Better for UI pagination, faster initial response
- Large pages (100): Better for batch processing, fewer API calls
- Default (20): Good balance for most use cases
Check hasNext Before Fetching
Check hasNext Before Fetching
Always check if there’s a next page before making the request:This prevents unnecessary API calls when you’ve reached the end.
Handle Rate Limits
Handle Rate Limits
Cache Results When Possible
Cache Results When Possible
Cache paginated results to reduce API calls:
Show Progress for Large Datasets
Show Progress for Large Datasets
Provide feedback when fetching many pages:
Pagination with Filters
Combine pagination with filtering:Pagination Limits
Maximum Page Size
- Maximum: 100 items per page
- Default: 20 items per page
- Minimum: 1 item per page
Maximum Pages
There is no hard limit on the number of pages, but:- Very large datasets may take time to process
- Consider using filters to narrow results
- Implement caching for frequently accessed data
Common Patterns
Infinite Scroll (UI)
Implement infinite scroll in your application:Page Navigation (UI)
Implement page-based navigation:Troubleshooting
Empty results on valid page
Empty results on valid page
Problem: Getting empty results even though pagination says there are more pagesPossible causes:
- Data was deleted between requests
- Filters are too restrictive
- Race condition with concurrent modifications
Inconsistent page counts
Inconsistent page counts
Problem: Total pages changes between requestsReason: This is normal! Data can be added or removed while you’re paginating.Solution:
- Use
hasNextinstead of relying ontotalPages - Implement refresh mechanisms
- Consider using timestamps to detect changes
Slow pagination performance
Slow pagination performance
Problem: Pagination is slow, especially on later pagesSolutions:
- Use larger page sizes (up to 100)
- Add filters to reduce total dataset
- Cache results when appropriate
- Consider using webhooks for real-time updates instead
Related Topics
Filtering
Learn how to filter results
Rate Limits
Understand API rate limiting
List Expenses
Expenses list endpoint
Error Handling
Handle pagination errors
Summary
- ✅ Use
pageandpageSizeparameters - ✅ Check
hasNextbefore fetching next page - ✅ Maximum page size is 100 items
- ✅ Add delays between requests for rate limiting
- ✅ Handle errors gracefully
- ✅ Cache results when possible
- ✅ Show progress for large datasets