Documents

A document is one file in your organization (an invoice, credit note, purchase order, receipt…), with its type, number, extracted data and every time it was received. The same bytes are stored once: uploading a file the organization already has returns the existing document and records the new arrival.

The document object

{
  "id": "Xb3kT9qLm2Pa",
  "doc_type": "invoice",
  "doc_subtype": "purchase_invoice",
  "extraction_status": "complete",
  "extraction_error": null,
  "hold_posting": false,
  "object_number": "INV-001",
  "file_name": "INV-001.pdf",
  "mime_type": "application/pdf",
  "file_size": 48213,
  "sha256": "9f2c…",
  "extracted_data": { "vendor_name": "Acme Supplies", "total": 11800 },
  "classification": { "station": "AP1", "confidence": 0.97, "work_record_id": "wr_123" },
  "extraction": { "station": "AP8", "confidence": 0.93, "work_record_id": "wr_123" },
  "parent_document_id": null,
  "parent_document": null,
  "parts": [],
  "created_at": "2026-11-16T10:00:00.000Z",
  "updated_at": "2026-11-16T10:05:00.000Z",
  "arrivals": [
    {
      "id": "a8Kp2Lm9Qx1Z",
      "channel": "email",
      "channel_ref": "<[email protected]>",
      "sender": "[email protected]",
      "received_at": "2026-11-15T10:00:00.000Z",
      "file_name": "INV-001.pdf",
      "work_record_id": null,
      "details": { "subject": "Invoice 001" },
      "created_at": "2026-11-16T10:00:00.000Z"
    }
  ]
}
FieldValues
doc_typeWhat the document is: invoice, proforma_invoice, credit_note, debit_note, quotation, purchase_order, receipt, payment_advice, statement, report, gst_certificate, contract, other; or bundle (a file holding several documents), junk (not a finance document), unclassified (on upload)
doc_subtypeThe finer kind, only for an invoice: purchase_invoice (billed to your organization) or sales_invoice (issued by it); otherwise null
extraction_statusreceived → classified → extracted → complete (nothing left to extract)
extraction_errorWhy extraction stopped, as { "reason", "station", "work_record_id", "at" }, or null. It's fixed where the document is processed, not here
hold_postingtrue when the document must not be posted; set by the processing line or a person
extracted_dataAny JSON object; its shape depends on the document type
arrivals[].channelemail, whatsapp, drive, upload, api

arrivals, parent_document and parts are included when you get one document or upload one, not in lists.

  • parent_document: the bundle this document was split from, as { "id", "file_name" }, or null.
  • parts: the documents split from this one (those whose parent_document_id is this id), by first page. Each is { "id", "file_name", "doc_type", "extraction_status", "object_number", "page_range" }: page_range comes from the part's split arrival (details.split_from set to this id, details.page_range). A part that was split again has doc_type bundle.

Upload a document

POST /api/v1/documents, multipart/form-data:

FieldRequiredNotes
fileyesUp to 12 MB
channelyesHow it arrived
channel_refnoThe channel's own id: email Message-ID, WhatsApp message id, Drive file id
sendernoEmail address, phone number or user
received_atnoWhen the channel received it, e.g. 2026-11-15T10:00:00Z
work_record_idnoThe orchestrator run that uploaded it
detailsnoA JSON object as a string, e.g. {"subject":"Invoice 001"}
curl -X POST https://documents.finopsbricks.com/api/v1/documents \
  -H "api-key: YOUR_KEY" -H "api-secret: YOUR_SECRET" \
  -F "[email protected]" \
  -F "channel=email" \
  -F "[email protected]" \
  -F "received_at=2026-11-15T10:00:00Z"

Returns 201 with the new document, or 200 when the organization already has these bytes:

{ "data": { "id": "Xb3kT9qLm2Pa", "extraction_status": "received", "arrivals": [ … ] }, "duplicate_file": true }

To skip sending a file you may already have, look it up first by its SHA-256: GET /api/v1/documents?sha256=<hex>.

List documents

GET /api/v1/documents

ParameterNotes
doc_type, doc_subtype, extraction_status, object_number, sha256Exact match
hold_posting, has_extraction_errortrue or false
created_at_from, created_at_toISO 8601 instants, inclusive
sort_bycreated_at (default) or updated_at
sort_orderDESC (default) or ASC
page, limitSee Pagination
curl "https://documents.finopsbricks.com/api/v1/documents?extraction_status=complete&doc_subtype=purchase_invoice&hold_posting=false" \
  -H "api-key: YOUR_KEY" -H "api-secret: YOUR_SECRET"

Get a document

GET /api/v1/documents/:id returns the document with its arrivals.

Download the file

GET /api/v1/documents/:id/file returns the stored bytes with their original content type.

curl -o INV-001.pdf https://documents.finopsbricks.com/api/v1/documents/Xb3kT9qLm2Pa/file \
  -H "api-key: YOUR_KEY" -H "api-secret: YOUR_SECRET"

Update a document

PUT /api/v1/documents/:id with a JSON body. Only the fields you send change.

FieldNotes
doc_typeOne of the types above
doc_subtypeOne the doc_type has, or null
extraction_statusMoves forward only
extraction_error{ "reason": "…", "station": "…", "work_record_id": "…", "at": "…" } (reason required), or null to clear it
hold_postingtrue or false
object_numberThe document's own number as printed
extracted_data, classification, extractionJSON objects, or null
parent_document_idAnother document in your organization, when this one was split out of it
curl -X PUT https://documents.finopsbricks.com/api/v1/documents/Xb3kT9qLm2Pa \
  -H "api-key: YOUR_KEY" -H "api-secret: YOUR_SECRET" \
  -H "content-type: application/json" \
  -d '{"doc_type":"invoice","doc_subtype":"purchase_invoice","extraction_status":"complete","object_number":"INV-001","extracted_data":{"total":11800}}'