Paginierung

Durchlaufe große Ergebnismengen mit cursorbasierter Paginierung.

Überblick

Listenendpunkte geben Ergebnisse mit cursorbasierter Paginierung zurück. Dadurch bleiben die Ergebnisse auch dann konsistent, wenn sich Daten zwischen Anfragen ändern.

Parameter

ParameterTypStandardBeschreibung
limitinteger20Einträge pro Seite (maximal 100)
cursorstringCursor aus der vorherigen Antwort

Antwort

{
  "data": [
    { "id": "conv_1", "created_at": "2025-01-15T10:00:00Z" },
    { "id": "conv_2", "created_at": "2025-01-15T09:30:00Z" }
  ],
  "pagination": {
    "has_more": true,
    "next_cursor": "eyJpZCI6ImNvbnZfMiJ9"
  }
}

Verwendung

Erste Seite

curl https://api.your-domain.com/v1/conversations?limit=20 \
  -H "Authorization: Bearer YOUR_API_KEY"

Nächste Seite

curl "https://api.your-domain.com/v1/conversations?limit=20&cursor=eyJpZCI6ImNvbnZfMiJ9" \
  -H "Authorization: Bearer YOUR_API_KEY"

Alle Seiten durchlaufen

async function fetchAll(endpoint) {
  const results = [];
  let cursor = undefined;

  do {
    const params = new URLSearchParams({ limit: "100" });
    if (cursor) params.set("cursor", cursor);

    const response = await fetch(`${endpoint}?${params}`, {
      headers: { Authorization: "Bearer YOUR_API_KEY" },
    });
    const { data, pagination } = await response.json();

    results.push(...data);
    cursor = pagination.has_more ? pagination.next_cursor : undefined;
  } while (cursor);

  return results;
}

Auf dieser Seite