Skip to main content

Overview

This example demonstrates how to upload a PDF file to create a new document in Factify.

Prerequisites

  • A valid API key from your Developer Dashboard
  • The Factify SDK installed

Code Example

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

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

async function uploadDocument() {
  const result = await factify.documents.create({
    payload: await openAsBlob("./contract.pdf"),
    title: "Q4 Sales Agreement",
  });

  console.log(`Document ID: ${result.createDocumentResponse?.document.id}`);
  return result.createDocumentResponse?.document;
}

uploadDocument();

Response

{
  "document": {
    "id": "doc_01h2xcejqtf2nbrexx3vqjhp41",
    "title": "Q4 Sales Agreement",
    "created_at": "2024-01-15T10:30:00Z",
    "current_version": {
      "id": "ver_01h2xcejqtf2nbrexx3vqjhp42"
    }
  }
}

Next Steps