Skip to main content

Overview

Documents in Factify are immutable - you cannot overwrite files. Instead, you create new versions to track changes while preserving the complete history.

Prerequisites

  • An existing document ID
  • A valid API key

Code Example

import { Factify } from "@factify/sdk";
import { openAsBlob } from "node:fs";

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

async function createVersion(documentId: string) {
  const result = await factify.versions.create({
    documentId,
    body: {
      payload: await openAsBlob("./contract-v2.pdf"),
    },
  });

  const version = result.createDocumentVersionResponse?.version;
  console.log(`Version ID: ${version?.id}`);
  return version;
}

createVersion("doc_01h2xcejqtf2nbrexx3vqjhp41");

List All Versions

Retrieve the complete version history for a document:
for await (const page of await factify.versions.list({
  documentId: "doc_01h2xcejqtf2nbrexx3vqjhp41"
})) {
  for (const version of page.listVersionsResponse?.items ?? []) {
    console.log(`${version.id} - ${version.createdAt}`);
  }
}

Response

{
  "version": {
    "id": "ver_01h2xcejqtf2nbrexx3vqjhp42",
    "document_id": "doc_01h2xcejqtf2nbrexx3vqjhp41",
    "created_at": "2024-01-16T14:00:00Z"
  }
}

Next Steps