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();
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,
});
}
{
"items": [...],
"pagination": {
"next_page_token": "eyJsYXN0X2lkIjoiZG9jXzAxaDJ4Y2VqcXRmMm5icmV4eDN2cWpocDQxIn0="
}
}
| Field | Description |
|---|
next_page_token | Opaque token for the next page (absent on last page) |
Parameters
| Parameter | Type | Description |
|---|
pageSize | number | Results per page (default: 50, max: 100) |
pageToken | string | Cursor from previous response |
Pagination uses opaque cursor tokens. Do not decode or construct tokens manually.
Best Practices
- Use auto-pagination - Let the SDK handle fetching pages for you
- Set appropriate page sizes - Larger pages mean fewer requests but more data per response
- Don’t store cursors long-term - Cursors may expire; fetch fresh data when needed
- Handle empty pages - The last page may have fewer items than
pageSize