Guides

Pagination

One pattern, every list endpoint. Stable in the face of inserts and re-orders.

Every list endpoint paginates the same way: pass a limit, get back a cursor, pass that cursor on the next request. Newest records first, always.

Parameters

  • limit — page size. Default 25, maximum 100. Lower limits trade roundtrips for latency; higher limits trade memory for throughput.
  • cursor— the value returned in the previous response's pagination.cursor. Omit on the first request to start from the beginning.

Response shape

text
GET /api/v1/orders?limit=25

{
  "data": [ /* … 25 orders … */ ],
  "pagination": {
    "cursor": "c1a2b3c4",
    "limit": 25,
    "hasMore": true
  }
}

Loop until pagination.hasMore is false. The final page's cursor may be null— that's fine, you're done anyway.

Cursors aren't offsets
A cursor isn't a page number — it's an opaque token. Don't try to skip ahead by guessing one, and don't cache cursors across long delays (24 hours+) — they may be invalidated.

A full loop

Iterate every order, page by page, in idiomatic Node and Python:

import process from "node:process";

const BASE = "https://theyutes.com/api/v1";
const TOKEN = process.env.THEYUTES_API_KEY;

async function* allOrders() {
  let cursor;
  do {
    const url = new URL(BASE + "/orders");
    url.searchParams.set("limit", "100");
    if (cursor) url.searchParams.set("cursor", cursor);

    const res = await fetch(url, {
      headers: { Authorization: `Bearer ${TOKEN}` },
    });
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
    const { data, pagination } = await res.json();

    yield* data;
    cursor = pagination.hasMore ? pagination.cursor : null;
  } while (cursor);
}

for await (const order of allOrders()) {
  console.log(order.number, order.totalKobo);
}