Skip to main content

Pagination and cursors

How list operations page with opaque keyset cursors, page size limits and the releases a page reads.

List operations return one page at a time. A page is a JSON object with the rows in data and an opaque cursor for the next page. When cursor is null, there are no more pages.

  • limit sets the page size: from 1 to 1,000 rows, 100 by default. A page also stays within 2 MiB of JSON, so it can hold fewer rows than limit.
  • A page can also be shorter when your remaining read units would not cover more rows. A shorter page is not the last page; only cursor: null is.
  • Pass the cursor back unchanged, with the same filters. Do not build or edit cursors; their format can change.
  • Cursors are keyset cursors. The order is stable, with a unique tie-breaker, so paging through one release neither skips nor repeats rows.
  • Each page is a separate call with its own X-Request-Id and its own read-unit charge.

Releases while you page

A list read uses the current release of each dataset, and every page names the releases it read in its releases list. A new release can be published while you page. To keep one consistent snapshot, compare each page's releases with the first page's and start again from the first page when they differ, as the example below does.

Example

js
let cursor = null;
let firstReleases = null;
do {
  const url = new URL('https://oysterlist.com/api/v1/series');
  url.searchParams.set('entity', 'entity:no.oslo');
  url.searchParams.set('limit', '500');
  if (cursor) url.searchParams.set('cursor', cursor);
  const response = await fetch(url, {
    headers: { authorization: `Bearer ${process.env.OYSTER_API_KEY}`, 'x-request-id': crypto.randomUUID() }
  });
  if (!response.ok) throw new Error((await response.json()).code);
  const page = await response.json();
  const releases = JSON.stringify(page.releases);
  firstReleases ??= releases;
  if (releases !== firstReleases) throw new Error('A new release was published while paging; start again.');
  for (const row of page.data) console.log(row.id, row.unit, row.frequency);
  cursor = page.cursor;
} while (cursor);

Paginated operations

Operations that use cursors
Operation Route
catalog.search GET /api/v1/catalog
datasets.list GET /api/v1/datasets
indicators.list GET /api/v1/indicators
entities.list GET /api/v1/entities
entities.children GET /api/v1/entities/{entityId}/children
series.list GET /api/v1/series
records.list GET /api/v1/records
changes.list GET /api/v1/changes
products.list GET /api/v1/products