Guide
Pagination
Long lists come a page at a time. When a response has next_cursor, pass it back as cursor to get the next page.
How it works
- Make the call as usual.
- If the response has
next_cursor, call again with the same parameters pluscursor=<next_cursor>. - Stop when
next_cursoris missing.
Treat the cursor as an opaque string and pass it back unchanged. Each page is a call and costs 1 credit. Routes that page are marked Paged in the reference.
import os
import requests
url = "https://api.tokconnect.com/v1/products/top"
params = {"keyword": "lip oil", "region": "US"}
headers = {"X-API-Key": os.environ["TOKCONNECT_API_KEY"]}
rows = []
while True:
body = requests.get(url, params=params, headers=headers, timeout=100).json()
rows += body["data"].get("items", [])
if not body.get("next_cursor") or len(rows) >= 300:
break
params["cursor"] = body["next_cursor"]const rows = [];
let cursor;
do {
const params = new URLSearchParams({ keyword: "lip oil", region: "US" });
if (cursor) params.set("cursor", cursor);
const res = await fetch(`https://api.tokconnect.com/v1/products/top?${params}`, {
headers: { "X-API-Key": process.env.TOKCONNECT_API_KEY },
});
const body = await res.json();
rows.push(...(body.data.items ?? []));
cursor = body.next_cursor;
} while (cursor && rows.length < 300);Cap your loop at the rows you need. Big lists can run to hundreds of rows.