Skip to main content

Pagination Parameters

ParameterTypeDefaultMaxDescription
pageinteger1-Page number (1-indexed)
page_sizeinteger20100Number of items per page

Request Example

GET /v1/platform/businesses/{business_id}/invoices/?page=1&page_size=50

Response Format

All paginated responses follow this structure:
{
  "count": 250,
  "next": "https://dev-backend.thredfi.com/v1/platform/businesses/{id}/invoices/?page=2",
  "previous": null,
  "results": [
    {
      "id": "invoice-uuid-1",
      ...
    },
    {
      "id": "invoice-uuid-2",
      ...
    }
  ]
}

Response Fields

FieldTypeDescription
countintegerTotal number of items across all pages
nextstring|nullURL for next page, or null if last page
previousstring|nullURL for previous page, or null if first page
resultsarrayArray of items for current page

Fetching All Pages

def get_all_invoices(business_id, token):
    """Fetch all invoices across all pages."""
    all_invoices = []
    url = f"https://dev-backend.thredfi.com/v1/platform/businesses/{business_id}/invoices/"

    while url:
        response = requests.get(
            url,
            headers={"Authorization": f"Bearer {token}"},
            params={"page_size": 100}  # Use max page size
        )

        data = response.json()
        all_invoices.extend(data['results'])

        # Move to next page
        url = data['next']

    return all_invoices

# Usage
invoices = get_all_invoices(business_id, business_token)
print(f"Total invoices: {len(invoices)}")

Performance Optimization

Use Maximum Page Size

Always use the maximum page_size (100) to minimize API calls:
params = {"page_size": 100}  # Fetch 100 items per request

Implement Cursor-Based Pagination (Future)

Cursor-based pagination is planned for future releases to improve performance on large datasets.

Filtering + Pagination

Combine filters with pagination for efficient data retrieval:
GET /v1/platform/businesses/{id}/invoices/
  ?status=unpaid
  &page=1
  &page_size=50
  &sort=-sent_at
response = requests.get(
    f"{base_url}/v1/platform/businesses/{business_id}/invoices/",
    headers={"Authorization": f"Bearer {token}"},
    params={
        "status": "unpaid",
        "page": 1,
        "page_size": 50,
        "sort": "-sent_at"  # Descending by sent_at
    }
)

Paginated Endpoints

The following endpoints support pagination:
  • /v1/platform/businesses/ - List businesses
  • /v1/platform/businesses/{id}/invoices/ - List invoices
  • /v1/platform/businesses/{id}/invoices/payments/ - List invoice payments
  • /v1/platform/businesses/{id}/bills/ - List bills
  • /v1/platform/businesses/{id}/bills/payments/ - List bill payments
  • /v1/platform/businesses/{id}/customers/ - List customers
  • /v1/platform/businesses/{id}/vendors/ - List vendors
  • /v1/platform/businesses/{id}/general-ledger/chart-of-accounts/ - List accounts
  • /v1/platform/businesses/{id}/general-ledger/journal-entries/ - List journal entries
See the API Reference for complete list.

Best Practices

Use maximum page size

Set page_size=100 to minimize API calls and improve performance.

Cache results

Cache paginated results when appropriate to reduce redundant API calls.

Monitor count field

Use the count field to show progress when fetching all pages.

Handle empty results

Always check if results array is empty before processing.

Next Steps