Skip to Content
Pagination

Pagination

Every endpoint returning several objects returns a list object:

{ "object": "list", "data": [ { "id": "alrt_5TgH2kLm8NpQ3rSv6wXy9A", "object": "alert", "…": "…" }, { "id": "alrt_4RfG1jKl7MoP2qRu5vWx8Z", "object": "alert", "…": "…" } ], "has_more": true }

Lists are ordered from the newest object to the oldest, and paginated with a cursor:

ParameterDescription
limitNumber of objects to return, between 1 and 100. Default: 20.
starting_afterAn object ID. Returns the objects that come after it in the list.

To walk a whole list, pass the ID of the last object of each page until has_more is false:

curl "https://api.skoup.ai/v1/brands/br_2xKq8Fh3LmN9pQrT4vWy6Z/alerts?limit=100" \ -H "Authorization: Bearer skoup_test_4eC39HqLyjWDarjtT1zdp7dc" curl "https://api.skoup.ai/v1/brands/br_2xKq8Fh3LmN9pQrT4vWy6Z/alerts?limit=100&starting_after=alrt_4RfG1jKl7MoP2qRu5vWx8Z" \ -H "Authorization: Bearer skoup_test_4eC39HqLyjWDarjtT1zdp7dc"
async function* allAlerts(brand) { let startingAfter while (true) { const url = new URL(`https://api.skoup.ai/v1/brands/${brand}/alerts`) url.searchParams.set('limit', '100') if (startingAfter) url.searchParams.set('starting_after', startingAfter) const page = await fetch(url, { headers: { Authorization: `Bearer ${process.env.SKOUP_API_KEY}` }, }).then((r) => r.json()) yield* page.data if (!page.has_more) return startingAfter = page.data.at(-1).id } }

A cursor stays valid even if new objects are created while you paginate: they appear at the top of the list and do not shift your pages.

Last updated on