Taiga

Pagination

Work through list endpoints with page tokens.

Most list endpoints return a page of results and a token for the next page.

{
  "items": [],
  "next_page_token": "",
  "prev_page_token": null
}

Pagination loop

Walk through pages

Request a page size. Use limit when the endpoint supports it.

curl "https://api.taigabilling.com/api/encounters/v4?limit=50" \
  -H "Authorization: Bearer $TAIGA_ACCESS_TOKEN"

Request the next page. Pass the returned next_page_token as page_token.

curl "https://api.taigabilling.com/api/encounters/v4?limit=50&page_token=$NEXT_PAGE_TOKEN" \
  -H "Authorization: Bearer $TAIGA_ACCESS_TOKEN"

Stop when the token is empty. Continue until next_page_token is empty or missing.

Don't rely on item counts.

Taiga enforces billing-provider NPI scope on list responses. Because filtering can happen after an upstream page is read, a page may contain fewer items than the requested limit. Use next_page_token, not item count, to decide whether more data may exist.

paginate.ts
let pageToken: string | undefined;

do {
  const url = new URL("https://api.taigabilling.com/api/encounters/v4");
  url.searchParams.set("limit", "50");

  if (pageToken) {
    url.searchParams.set("page_token", pageToken);
  }

  const response = await fetch(url, {
    headers: {
      Authorization: `Bearer ${process.env.TAIGA_ACCESS_TOKEN}`,
    },
  });

  if (!response.ok) {
    throw new Error(`Request failed: ${response.status}`);
  }

  const page = await response.json();

  for (const item of page.items ?? []) {
    // Process item.
  }

  pageToken = page.next_page_token || undefined;
} while (pageToken);

On this page