Skip to main content

Apply OCR Extraction to Invoice

POST 

/api/purchase-invoices/:purchaseInvoice/ocr-apply

Apply reviewed OCR extraction results to a purchase invoice. Synchronous — the invoice is updated immediately.

Required scope: purchase-orders:write

Grant this scope to your token under Settings → Developer → Personal Access Tokens.

Body fields:

  • extraction_id (integer, optional) — the extraction whose unmatched-line decisions should be saved.
  • header.supplier_invoice_number (string, optional, max 255) and header.purchase_invoice_date (date, optional) — update the invoice header. Null values are ignored (fields cannot be blanked here).
  • lines (array, required, min 1) — the resulting invoice lines. Each line needs quantity_invoiced (numeric, required, min 0), optional unit_price (numeric, min 0), and either purchase_order_line_id (existing PO line) or financial_line_id (existing cost line).
  • unmatched_lines (array, optional) — snapshot of unmatched document lines; set ignored: true on lines to exclude. Saved onto the extraction for future reads.

Line replacement semantics: entries with purchase_order_line_id fully sync the invoice's product lines — invoice lines whose PO line is not in the payload are deleted, new ones are created, and existing ones are updated. Entries with financial_line_id update the invoice's cost lines, or copy the PO's planned cost line onto the invoice if not present (the PO's own line is never modified).

After applying, the invoice's approval status is re-evaluated: price or quantity variances against the PO (or invoicing more than was received) set pending_approval; otherwise auto_approved.

Archived invoices return 422. Requires the purchase-orders:write token scope.

Request

Responses

OK

Response Headers
    Content-Type