Skip to content

Pagination

Read forward and backward through cursor-based list responses.

Updated View as Markdown

Await a list call to read one page, or use async iteration to read across pages. Each page has data and hasMore fields.

Iterate resources

for await (const practice of affinity.practices.iterate({ limit: 25 })) {
  console.log(practice.id, practice.name);
}

The SDK fetches the next page as needed and preserves your filters. Breaking the loop stops further page requests. Iteration is forward-only; use explicit list calls for backward paging. List endpoints without cursor parameters return an ordinary response.

Collect a bounded array

const practices = [];
for await (const practice of affinity.practices.iterate({ limit: 25 })) {
  practices.push(practice);
  if (practices.length === 100) break;
}

Stop the loop when you have collected the required number of records.

Read the first page

const page = await affinity.forPractice(practiceId).orders.list({
  limit: 25,
});

Read the next page

Pass the last resource ID to startingAfter.

if (page.hasMore && page.data.length > 0) {
  const nextPage = await affinity.forPractice(practiceId).orders.list({
    limit: 25,
    startingAfter: page.data.at(-1)!.id,
  });
}

Read the previous page

Pass the first resource ID to endingBefore.

if (page.data.length > 0) {
  const previousPage = await affinity.forPractice(practiceId).orders.list({
    limit: 25,
    endingBefore: page.data[0]!.id,
  });
}

Do not pass startingAfter and endingBefore in the same request.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close