Getting started

Quickstart

Seven requests: a key, a queue, an upload, the wait, the extracted fields and the approval.

Before you start

You need a DocuFlow workspace and a role that can create queues and approve documents. Everything else below is created as you go.

Base URLhttps://docuflow.pendral.io/api/v2

Node.js and TypeScript

In Node.js, Bun, Deno or an edge runtime, use the TypeScript SDK. It types every request and response, retries safely and follows documents live. The cURL walkthrough below makes the same requests by hand.

npm install @pendral/docuflow
import { readFile } from "node:fs/promises";
import DocuFlow from "@pendral/docuflow";
const docuflow = new DocuFlow(); // reads DOCUFLOW_API_KEY
const { documents } = await docuflow.documents.upload({
queue: "invoices",
files: { data: await readFile("invoice-1042.pdf"), name: "invoice-1042.pdf" },
});
const document = await docuflow.documents.waitFor(documents[0].id, { status: "needs_review" });
const { values } = await docuflow.documents.fields.get(document.id);
await docuflow.documents.approve(document.id);

The walkthrough

  1. Create a key

    Keys live under Developers → API keys. A key belongs to the workspace you were in when you made it and acts as you, narrowed to the scopes you pick. For this walkthrough it needs queues:create, documents:create, documents:read and documents:approve. The token is shown once; keep it in an environment variable.

    export DOCUFLOW_API_KEY="dfk_..."
  2. Check that it works

    whoami needs no permission beyond a valid key. It answers with the workspace the key acts in and the permissions it really holds, which is the quickest way to find out why something later says 403.

    curl "https://docuflow.pendral.io/api/v2/whoami" \
    -H "Authorization: Bearer $DOCUFLOW_API_KEY"
  3. Create a queue

    A queue is a family of documents with one schema: the fields to extract. automation: "never" sends every document to review, so the next steps have something to approve.

    curl -X POST "https://docuflow.pendral.io/api/v2/queues" \
    -H "Authorization: Bearer $DOCUFLOW_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
    "name": "Invoices",
    "automation": "never",
    "fields": [
    { "key": "invoiceNumber", "label": "Invoice number", "type": "string", "required": true },
    { "key": "invoiceDate", "label": "Invoice date", "type": "date" },
    { "key": "total", "label": "Total due", "type": "number" }
    ]
    }'

    The response is 201 with the queue, including its id and slug.

  4. Upload a document

    Uploads are multipart/form-data: one or more file parts and the queue, by queueId or by slug as queue. The call returns as soon as the file is stored; extraction runs in the background.

    curl -X POST "https://docuflow.pendral.io/api/v2/documents" \
    -H "Authorization: Bearer $DOCUFLOW_API_KEY" \
    -H "Idempotency-Key: upload-invoice-1042" \
    -F "file=@invoice-1042.pdf" \
    -F "queue=invoices"
    201 Created
    {
    "documents": [
    { "id": "clx9k2m4p0001qh8z3v7d5f2a", "name": "invoice-1042.pdf", "duplicate": false }
    ]
    }

    Retries are safe

    With an Idempotency-Key, sending the same upload again after a timeout returns the first answer instead of a second document. Idempotency.
  5. Wait for needs_review

    A document moves received → processing → needs_review, then to approved or rejected, and exported once a destination has it. failed means processing stopped. Poll the document until its status settles:

    curl "https://docuflow.pendral.io/api/v2/documents/{documentId}" \
    -H "Authorization: Bearer $DOCUFLOW_API_KEY"

    Or hold one connection open and watch it move: GET /api/v2/events is a server-sent event stream of every document's status, stage and progress in the workspace.

    curl -N "https://docuflow.pendral.io/api/v2/events" \
    -H "Authorization: Bearer $DOCUFLOW_API_KEY"

    In production, don't poll

    Subscribe a webhook to document.needs_review and you are told the moment the data is ready. Webhooks.
  6. Read the fields

    values is the extracted data as a plain nested object, the same shape webhooks and exports send. fields has one row per value with its page, bounding box, confidence and status.

    curl "https://docuflow.pendral.io/api/v2/documents/{documentId}/fields" \
    -H "Authorization: Bearer $DOCUFLOW_API_KEY"
    200 OK
    {
    "documentId": "clx9k2m4p0001qh8z3v7d5f2a",
    "status": "needs_review",
    "runId": "clx9k2m4p0002qh8zj1c8w3rb",
    "values": { "invoiceNumber": "INV-1042", "invoiceDate": "2026-09-28", "total": 1240 },
    "fields": [
    { "path": "invoiceNumber", "value": "INV-1042", "page": 1, "confidence": 0.98, "status": "extracted", … },
    …
    ]
    }
  7. Approve

    Approving accepts the current values. Correct a field first with PATCH /api/v2/documents/{id}/fields if it needs it; blocking validation errors refuse the approval unless you pass force: true.

    curl -X POST "https://docuflow.pendral.io/api/v2/documents/{documentId}/approve" \
    -H "Authorization: Bearer $DOCUFLOW_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{ "note": "Checked against the purchase order" }'

    The document is now approved, document.approved goes out to your webhooks, and any destination on the queue exports it.

Where to go next