Skip to main content

Overview

All list endpoints use cursor-based pagination for reliable, consistent results. The SDK returns an async iterable that you can consume using for await...of. The SDK handles pagination automatically:
import { Factify } from "@factify/sdk";

const factify = new Factify({
  bearerAuth: process.env.FACTIFY_KEY,
});

async function run() {
  const result = await factify.documents.list({
    pageSize: 10,
  });

  // Auto-pagination: iterate through all pages automatically
  for await (const page of result) {
    for (const doc of page.listDocumentsResponse?.items ?? []) {
      console.log(`${doc.title} (${doc.id})`);
    }
  }
}

run();

Manual Pagination

For manual control over pagination, use the pageToken from the response:
// First page
const result = await factify.documents.list({ pageSize: 10 });
const nextToken = result.listDocumentsResponse?.pagination?.nextPageToken;

// Next page
if (nextToken) {
  const nextPage = await factify.documents.list({
    pageToken: nextToken,
    pageSize: 10,
  });
}

Pagination Response

{
  "items": [...],
  "pagination": {
    "next_page_token": "eyJsYXN0X2lkIjoiZG9jXzAxaDJ4Y2VqcXRmMm5icmV4eDN2cWpocDQxIn0="
  }
}
FieldDescription
next_page_tokenOpaque token for the next page (absent on last page)

Parameters

ParameterTypeDescription
pageSizenumberResults per page (default: 50, max: 100)
pageTokenstringCursor from previous response
Pagination uses opaque cursor tokens. Do not decode or construct tokens manually.

Best Practices

  1. Use auto-pagination - Let the SDK handle fetching pages for you
  2. Set appropriate page sizes - Larger pages mean fewer requests but more data per response
  3. Don’t store cursors long-term - Cursors may expire; fetch fresh data when needed
  4. Handle empty pages - The last page may have fewer items than pageSize