---
title: "Create a DRAFT invoice from an uploaded invoice document's extraction"
method: POST
path: "/companies/{companyId}/ar/drafts/from-document"
tags: ["AR/AP"]
---

# Create a DRAFT invoice from an uploaded invoice document's extraction

`POST /companies/{companyId}/ar/drafts/from-document`

## Request

- Base URL: `https://api.medianfi.com/api/v1`
- URL: `https://api.medianfi.com/api/v1/companies/{companyId}/ar/drafts/from-document`
- Auth: HTTP bearer

DARK — 404s unless ar_ap_items_enabled. Body {documentId}. Turns the document's latest extraction (documents pipeline evidence) into a draft through the composer aggregate; the draft references the source document (document_id + sourceMetadata.documentId). Fields are never guessed: a missing/incomplete extraction (wrong document type, unassigned document, no extraction row, failed extraction, missing amount/customer/issue date, or a document already linked to a receivable) is a 422 whose error.extensions.reasons lists every applicable gap. Extraction line items become composer lines only when they reconcile exactly to the invoice total; otherwise a single line carries the known total. Never auto-posts — issue/send stay explicit.

## Request body

- object
  - `documentId` string, uuid, required

## Response `201`

Draft created: { success, data: { draftInvoiceId } }

## Other responses

- `401`: Authentication required
- `404`: Document not found or AR/AP items not enabled
- `422`: Extraction missing/incomplete or document ineligible; error.extensions.reasons enumerates every applicable reason.

---

[API](https://skmtc.dev/medianfi/apis/median-api.md) · [All operations](https://skmtc.dev/medianfi/apis/median-api/llms.txt) · [OpenAPI document](https://skmtc.dev/medianfi/apis/median-api/revisions/20090ea32b0d?raw)
