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.
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_KEYconst { 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
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:readanddocuments:approve. The token is shown once; keep it in an environment variable.export DOCUFLOW_API_KEY="dfk_..."Check that it works
whoamineeds 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 says403.curl "https://docuflow.pendral.io/api/v2/whoami" \-H "Authorization: Bearer $DOCUFLOW_API_KEY"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
201with the queue, including itsidandslug.Upload a document
Uploads are
multipart/form-data: one or morefileparts and the queue, byqueueIdor by slug asqueue. 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 anIdempotency-Key, sending the same upload again after a timeout returns the first answer instead of a second document. Idempotency.Wait for needs_review
A document moves
received → processing → needs_review, then toapprovedorrejected, andexportedonce a destination has it.failedmeans processing stopped. Poll the document until itsstatussettles: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/eventsis a server-sent event stream of every document'sstatus,stageandprogressin 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 todocument.needs_reviewand you are told the moment the data is ready. Webhooks.Read the fields
valuesis the extracted data as a plain nested object, the same shape webhooks and exports send.fieldshas 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", … },…]}Approve
Approving accepts the current values. Correct a field first with
PATCH /api/v2/documents/{id}/fieldsif it needs it; blocking validation errors refuse the approval unless you passforce: 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.approvedgoes out to your webhooks, and any destination on the queue exports it.