Skip to content

Parsing

POST /v1/invoices/parse turns UBL, CII or a ZUGFeRD / Factur-X PDF into one JSON model that follows the EN 16931 semantic model.

parse.ts

// Parse an invoice into canonical EN 16931 JSON (Node 20+).
import { readFile } from "node:fs/promises";

const res = await fetch(`${process.env.EINV_BASE}/v1/invoices/parse?store=false`, {
  method: "POST",
  headers: { authorization: `Bearer ${process.env.EINV_KEY}`, "content-type": "application/xml" },
  body: await readFile(process.argv[2] ?? "invoice.xml"),
});
const { invoice, lossless, warnings } = await res.json();
console.log(invoice.id, invoice.currency, invoice.totals.payable, `${invoice.lines.length} lines`, lossless ? "lossless" : `${warnings.length} warnings`);

The canonical model

Field names describe the business term; each field carries its BT/BG number in the JSON Schema (components.schemas.Invoice).

Excerpt of the result for the official sample:

{
  "documentKind": "invoice",
  "id": "123456XX",
  "issueDate": "2016-04-04",
  "typeCode": "380",
  "currency": "EUR",
  "buyerReference": "04011000-12345-03",
  "seller": { "name": "[Seller name]", "vatId": "DE 123456789", "address": { "city": "[Seller city]", "countryCode": "DE" } },
  "buyer": { "name": "[Buyer name]" },
  "totals": { "lineNet": "314.86", "taxExclusive": "314.86", "tax": "22.04", "taxInclusive": "336.9", "payable": "336.9" },
  "vatBreakdown": [{ "taxableAmount": "314.86", "taxAmount": "22.04", "category": "S", "rate": "7" }],
  "lines": [{ "id": "Zeitschrift [...]", "quantity": "1", "unitCode": "XPP", "netAmount": "288.79", "price": { "net": "288.79" }, "vat": { "category": "S", "rate": "7" }, "item": { "name": "Zeitschrift [...]" } }]
}

Note "336.9": the sample writes the amount with one decimal, and the model keeps it exactly as written.

Rules:

  • Amounts, quantities and rates are decimal strings exactly as in the source. 19, 19.0 and 19.00 stay as written.
  • Dates are ISO YYYY-MM-DD whatever the syntax.
  • Code values (UNTDID, ISO 3166, UN/ECE Rec 20, EAS, ICD) are kept verbatim.
  • Payment terms (BT-20) keep their whitespace, because XRechnung Skonto lines are line-based.

Nothing is silently dropped

Every element and attribute of the source is accounted for. Data that the EN 16931 model cannot hold — XRechnung Extension elements, for example — is listed in warnings with code: "unmapped_element", its path, value and line, and lossless is false. Syntax-only values without a business term (such as UBL cbc:NetworkID) appear as syntax_only_dropped.

schemaConformant: false with model_constraint warnings means the document is missing data that the model requires (an invalid invoice can still be parsed).

Comparing two invoices

POST /v1/invoices/compare takes two documents as JSON — { "a": { "document": "…" }, "b": { "document": "…", "encoding": "base64" } } — parses both and compares them field by field in the EN 16931 model. Syntax (UBL or CII), element order and number formatting (100 and 100.00) are not differences. Each difference has the field path, kind (changed, added, removed), both values and sensitive: true for amounts, tax data and bank or party identifiers. Use it to check a conversion or a repair, or to compare what your ERP sent with what a platform received. Comparing is recorded but not billed, and nothing is stored.

Parsing does not validate

Parsing reads the document; it does not run the business rules. Call validate for a verdict.