Skip to main content

Overview

Retrieve all documents in your organization with support for pagination.

Prerequisites

  • A valid API key

Code Example

import { Factify } from "@factify/sdk";

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

async function listDocuments() {
  // Auto-pagination handles fetching all pages
  for await (const page of await factify.documents.list({ pageSize: 50 })) {
    for (const doc of page.listDocumentsResponse?.items ?? []) {
      console.log(`${doc.id}: ${doc.title}`);
    }
  }
}

listDocuments();

Pagination Options

Control the number of results per page:
// Fetch with custom page size
for await (const page of await factify.documents.list({
  pageSize: 20
})) {
  for (const doc of page.listDocumentsResponse?.items ?? []) {
    console.log(`${doc.id}: ${doc.title}`);
  }
}

Manual Pagination

If you need manual control over pagination:
let pageToken: string | undefined;

do {
  const result = await factify.documents.list({
    pageSize: 50,
    pageToken
  });

  const response = result.listDocumentsResponse;
  for (const doc of response?.items ?? []) {
    console.log(doc.title);
  }

  pageToken = response?.pagination?.nextPageToken;

} while (pageToken);

Response

{
  "items": [
    {
      "id": "doc_01h2xcejqtf2nbrexx3vqjhp41",
      "title": "Q4 Sales Agreement",
      "created_at": "2024-01-15T10:30:00Z",
      "current_version": {
        "id": "ver_01h2xcejqtf2nbrexx3vqjhp42"
      }
    },
    {
      "id": "doc_01h2xcejqtf2nbrexx3vqjhp42",
      "title": "Employee Handbook",
      "created_at": "2024-01-14T09:00:00Z",
      "current_version": {
        "id": "ver_01h2xcejqtf2nbrexx3vqjhp43"
      }
    }
  ],
  "pagination": {
    "next_page_token": "eyJsYXN0X2lkIjoi..."
  }
}

Parameters

ParameterTypeDescription
pageSizenumberResults per page (max: 100)
pageTokenstringPagination token from previous response

Next Steps