Skip to main content
Docs/Node.js SDK/Pagination
SDK Reference

Pagination

List endpoints return cursor-based pages. The SDK provides two ways to paginate: manual page fetching and an async iterator.

Manual pagination

TypeScript

// First page
const { data } = await client.agents.list({ limit: 20 });
const agents = data.agents;

// Next page — pass the cursor from the previous response
if (data.next_cursor) {
  const { data: page2 } = await client.agents.list({
    limit: 20,
    after: data.next_cursor,
  });
}

Async iterator (autoPaginate)

TypeScript

// Iterate all agents across all pages automatically
for await (const agent of client.agents.autoPaginate({ limit: 50 })) {
  console.log(agent.public_id, agent.name);
}

autoPaginate() fetches pages on demand as you iterate. It stops when there are no more pages. The optional limit controls page size, not total results.

Which resources support autoPaginate

agentscallsphoneNumbersknowledgeBases

Collecting all results into an array

TypeScript

const allAgents = [];
for await (const agent of client.agents.autoPaginate()) {
  allAgents.push(agent);
}
// or with a helper:
async function collectAll<T>(gen: AsyncGenerator<T>): Promise<T[]> {
  const items: T[] = [];
  for await (const item of gen) items.push(item);
  return items;
}

const agents = await collectAll(client.agents.autoPaginate());

Cursor-based pagination note

Cursors are opaque strings — do not parse or store them long-term. They may expire. For resumable exports, use from_date / to_date filters instead.

Pagination - Node.js SDK - Staffify