Documentation / Advanced

Pagination

Handle large result sets with pagination

Pagination

Efficiently handle large result sets by implementing pagination in your API requests.

Basic Pagination

Use the Offset and Limit parameters to paginate through results:

GET /api/v2/admin/pages?Offset=0&Limit=50   // First page
GET /api/v2/admin/pages?Offset=50&Limit=50  // Second page
GET /api/v2/admin/pages?Offset=100&Limit=50 // Third page

Response Structure

Paginated responses include metadata about the result set:

{
  "Items": [...],           // Current page of results
  "TotalItemsCount": 237,   // Total items matching the query
  "Offset": 0,              // Current offset
  "Limit": 50               // Items per page
}

Calculating Total Pages

const totalPages = Math.ceil(response.TotalItemsCount / response.Limit);
const currentPage = Math.floor(response.Offset / response.Limit) + 1;

Best Practices

  • Set reasonable limits: Default to 50 items per page, max 100
  • Cache total counts: TotalItemsCount can be expensive on large datasets
  • Use consistent ordering: Always specify Order_By for predictable pagination
  • Handle empty pages: Check if Items array is empty before processing

Cursor-Based Pagination (Coming Soon)

For real-time data streams, cursor-based pagination will be available:

GET /api/v2/admin/pages?cursor=eyJpZCI6MTIzfQ&Limit=50

⚡ Performance Tip

Large offsets (e.g., Offset=10000) can be slow. For deep pagination, consider filtering by date ranges instead.

Code Examples

// JavaScript: Paginate Through All Items
const fetchAllPages = async (token) => {
  const limit = 50;
  let offset = 0;
  const allItems = [];
  
  while (true) {
    const response = await fetch(
      `https://your-site.webinone.com/api/v2/admin/pages?Offset=${offset}&Limit=${limit}`,
      {
        headers: {
          'Authorization': `Bearer ${token}`
        }
      }
    );
    
    const data = await response.json();
    allItems.push(...data.Items);
    
    // Check if we've fetched all items
    if (allItems.length >= data.TotalItemsCount) {
      break;
    }
    
    offset += limit;
  }
  
  return allItems;
};

// Python: Generator for Memory-Efficient Pagination
def fetch_pages_paginated(client, page_size=50):
    offset = 0
    while True:
        response = client.get(
            '/api/v2/admin/pages',
            params={'Offset': offset, 'Limit': page_size}
        )
        data = response.json()
        
        # Yield items from current page
        yield from data['Items']
        
        # Check if we've reached the end
        if offset + page_size >= data['TotalItemsCount']:
            break
        
        offset += page_size

# Usage
for page in fetch_pages_paginated(client):
    print(page['Name'])