Pagination

Token-Based Pagination

When a query returns more records than fit in a single page, the API splits the result across multiple pages. Each response includes a pagination object with the current page count and a next_url to fetch the next page.

How it works

  1. Make your initial request with the required query parameters.
  2. Check the pagination object in the response.
  3. If next_url is present, it contains a relative URL with all original parameters plus an encrypted token_id.
  4. Prepend the base URL (https://api.apeek.io/api/v1) to next_url and make a GET request.
  5. Repeat until next_url is null, which means all records have been returned.

Pagination fields

Field Type Description
count string Number of records returned in the current page
next_url string | null Relative URL for the next page (includes all original query parameters and an encrypted token_id). null when there are no more results.

Example response with pagination

{
  "status": "OK",
  "message": "Data retrieved successfully",
  "meta": {
    "schema_version": "1.0",
    "frequency": "Weekly",
    "fields": {
      "date": "string (YYYY-MM-DD)",
      "series": "string",
      "value": "numerical string"
    }
  },
  "pagination": {
    "count": "10000",
    "next_url": "/economic-data/ui_weekly_claims?series=initial_claims_sa,continued_claims_sa&date_from=2025-01-01&date_to=2026-01-01&token_id=7c1b453e164b..."
  },
  "data": [ ... ]
}

Last page (no more results)

When the final page is reached, next_url is null:

"pagination": {
  "count": "347",
  "next_url": null
}

Fetching all pages (Python)

import requests

BASE_URL = "https://api.apeek.io/api/v1"

params = {
    "series": "initial_claims_sa,continued_claims_sa",
    "date_from": "2025-01-01",
    "date_to": "2026-01-01",
    "api_key": "your_api_key_here"
}

all_records = []
response = requests.get(
    f"{BASE_URL}/economic-data/ui_weekly_claims",
    params=params
)
result = response.json()
all_records.extend(result["data"])

while result["pagination"].get("next_url"):
    response = requests.get(
        f"{BASE_URL}{result['pagination']['next_url']}"
    )
    result = response.json()
    all_records.extend(result["data"])

print(f"Total records fetched: {len(all_records)}")

Important notes

  • Do not construct or modify token_id values yourself. Always use the next_url returned by the API.
  • Each next_url already contains all the original query parameters. You only need to prepend the base URL.
  • Pagination tokens are encrypted and tied to your original query. Using a token from a different query will result in an error.