Skip to main content

Pagination Guide

Many endpoints support cursor-based pagination to efficiently navigate through large result sets. Here’s how to use it:

Basic Usage

Most list endpoints support two query parameters:
  • limit - Number of results per page (1-25, default varies by endpoint)
  • cursor - Opaque token for fetching the next page

Making Your First Request

curl "https://api.polyrouter.io/functions/v1/markets?limit=10" \
  -H "X-API-Key: 5fa709a5-0634-44c3-a991-57166d3c376d"
The response includes a pagination object:
{
  "markets": [...],
  "pagination": {
    "total": 150,
    "limit": 10,
    "has_more": true,
    "next_cursor": "eyJwbGF0Zm9ybXMiOnsia2Fsc2hpIjp7..."
  }
}

Getting the Next Page

Use the next_cursor from the previous response:
curl "https://api.polyrouter.io/functions/v1/markets?limit=10&cursor=eyJwbGF0Zm9ybXMiOnsia2Fsc2hpIjp7..." \
  -H "X-API-Key: 5fa709a5-0634-44c3-a991-57166d3c376d"

Complete Example

  • JavaScript
  • Python
  • cURL
async function fetchAllMarkets() {
  const allMarkets = [];
  let cursor = null;
  let hasMore = true;

  while (hasMore) {
    const url = cursor 
      ? `https://api.polyrouter.io/functions/v1/markets?cursor=${cursor}&limit=25`
      : `https://api.polyrouter.io/functions/v1/markets?limit=25`;
    
    const response = await fetch(url, {
      headers: {
        'X-API-Key': '5fa709a5-0634-44c3-a991-57166d3c376d'
      }
    });
    
    const data = await response.json();
    allMarkets.push(...data.markets);
    
    hasMore = data.pagination.has_more;
    cursor = data.pagination.next_cursor;
  }
  
  return allMarkets;
}

Important Notes

Changing filters mid-pagination: If you change query parameters (like platform, status, or query) between requests, the cursor will be invalidated. Start pagination from the first page when changing filters.
Cursor lifespan: Cursors are designed for immediate use within a pagination session. Don’t store them long-term as they may become invalid.

Pagination Tips

  1. Choose appropriate limits:
    • Use limit=25 (maximum) for bulk operations
    • Use smaller limits (5-10) for real-time updates
    • Default limits vary by endpoint
  2. Check for more pages: Always check has_more or whether next_cursor is null before making another request
  3. Rate limits: Even with cursors, you’re still subject to rate limits (10 req per minute during beta)
  4. Platform filtering: When using platform parameter, only one platform value is supported per query (not comma-separated)