Conversion
POST /v1/invoices/convert?target=… — target is a syntax (ubl, cii) or a format id.
| From | To |
|---|---|
| XRechnung 3.0 UBL / CII | XRechnung 3.0 CII / UBL, Peppol BIS Billing 3.0, ZUGFeRD / Factur-X PDF (profile XRECHNUNG, EN 16931 or EXTENDED), Facturae 3.2.2, KSeF FA(3) |
| EN 16931 UBL / CII | EN 16931 CII / UBL, Peppol BIS Billing 3.0, ZUGFeRD / Factur-X PDF (profile EN 16931 or EXTENDED), Facturae 3.2.2, KSeF FA(3) |
| Peppol BIS Billing 3.0 | EN 16931 CII, Facturae 3.2.2, KSeF FA(3) |
| ZUGFeRD / Factur-X (PDF or XML; BASIC, EN 16931, EXTENDED) | EN 16931 UBL |
| Facturae 3.2.x | EN 16931 UBL or CII |
| KSeF FA(3) | EN 16931 UBL or CII |
Factur-X MINIMUM and BASIC WL have no invoice lines and are not converted. Conversion to Facturae and KSeF needs data that EN 16931 does not carry (Spanish person and residence types, Polish annotations); you pass it as options, it is never guessed. See the two sections on Facturae and KSeF output below.
ZUGFeRD / Factur-X output
target=zugferd-facturx returns a PDF/A-3b document, base64-encoded in document, with target.mediaType = "application/pdf" and target.encoding = "base64". The PDF shows the invoice on a readable page and embeds the CII as factur-x.xml (relationship Alternative), with Factur-X XMP metadata, embedded fonts and an sRGB output intent. Before it is returned, the PDF goes through the same validation as an uploaded one: the Factur-X rules of the profile and, where the PDF checker is enabled, veraPDF for PDF/A-3.
zugferd.sh
#!/usr/bin/env bash
# Create a ZUGFeRD / Factur-X PDF (PDF/A-3b, XML embedded as factur-x.xml) from an XRechnung or EN 16931 invoice.
set -euo pipefail
curl -sS --fail-with-body "$EINV_BASE/v1/invoices/convert?target=zugferd-facturx&store=false" \
-H "Authorization: Bearer $EINV_KEY" \
-H "Content-Type: application/xml" \
-H "Idempotency-Key: zugferd-$(date +%s)" \
--data-binary @"${1:-invoice.xml}" \
| node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const r=JSON.parse(s);require("fs").writeFileSync("invoice.pdf",Buffer.from(r.document,"base64"));console.log(r.validation.status, r.target.mediaType)})'
The profile follows the source: XRechnung becomes profile XRECHNUNG, every other EN 16931 invoice profile EN 16931. Pass profile=EXTENDED (or EN 16931, XRECHNUNG) to choose it. An EXTENDED PDF carries the guideline urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended, the XMP conformance level EXTENDED, and is checked with the Factur-X 1.09.2 EXTENDED Schema and Schematron (and veraPDF where enabled). target.profile names the profile of the returned PDF. The conversion writes the EN 16931 data of the source; it does not add EXTENDED-only data.
Peppol output
target=peppol-bis-billing sets the Peppol specification and process identifiers and validates the result with the OpenPeppol rules. Peppol has stricter rules than EN 16931 (for example a buyer reference or order reference, and electronic addresses from the Peppol EAS list); when the source does not meet them you get 422 conversion_output_invalid with the Peppol rule ids.
EN 16931 to Facturae 3.2.2
target=facturae returns one Facturae 3.2.2 invoice (modality I, issuer type EM, or RE for a self-billed invoice 389). It is checked with the Facturae XML Schema and the calculation rules FAC-R01..R11 / FAC-B01..B05 before it is returned.
The file is not signed. FACe and most Spanish platforms require a XAdES signature made with the issuer's certificate, which this service does not hold. The result carries the warning facturae_unsigned and the validation the warning FAC-S01. Sign the file before sending it and do not change it afterwards.
Facturae needs data EN 16931 does not carry. Send it as JSON with the document (the options cannot be passed in the query string):
{
"document": "<Invoice …>",
"target": "facturae",
"facturae": {
"seller": { "personType": "J", "residenceType": "R" },
"buyer": {
"personType": "J", "residenceType": "R",
"administrativeCentres": [
{ "code": "L01280796", "role": "01", "address": { "line1": "Plaza de la Villa, 4", "postcode": "28005", "city": "Madrid", "province": "Madrid", "countryCode": "ES" } }
]
},
"language": "es"
}
}
| Option | Facturae element | Notes |
|---|---|---|
personType (F / J) |
PersonTypeCode | Required for seller and buyer |
residenceType (R / U / E) |
ResidenceTypeCode | Required. For R the ES prefix of the VAT identifier is removed |
taxId |
TaxIdentificationNumber | Only when the party has no VAT identifier (BT-31 / BT-48); reads back as that VAT identifier (derived) |
individual (name, firstSurname, secondSurname) |
Individual | Required for F; joined with spaces it must equal the party name |
province |
Province | Only when the address has no country subdivision; Facturae requires a province |
administrativeCentres |
AdministrativeCentres | DIR3 centres for FACe (01 oficina contable, 02 órgano gestor, 03 unidad tramitadora, …) with their address |
language |
LanguageName | Required |
Missing values fail with 422 target_data_required; details.missing names each field and the option to pass. allowDataLoss does not skip this check. Values computed from the invoice: TotalCost (= BT-131 + line allowances − line charges), TotalTaxesWithheld 0.00, TotalOutstandingAmount and TotalExecutableAmount (BT-112 − BT-113), the batch totals and BatchIdentifier (tax number + invoice number), and a unit price per unit when BT-149 is not 1.
Mapping: BT-1 InvoiceNumber (max. 20 characters, no series), BT-3 380 → FC, 389 → AF; BT-12 ReceiverContractReference, BT-13 ReceiverTransactionReference (max. 20 each, invoice level), BT-25 RelatedInvoice, BT-72 OperationDate, BG-14 InvoicingPeriod, the first note InvoiceAdditionalInformation and further notes LegalReference, BG-23 TaxesOutputs (S, Z, E, O as IVA 01; L as IGIC 03; M as IPSI 02; E and O with SpecialTaxableEvent 01 / 02 and the exemption reason), document and line allowances and charges as discounts and surcharges, BG-16 one Installment (due date BT-9 required; means 10, 20, 21, 30, 48, 59, 97), unit codes with a Facturae UnitOfMeasure (C62, HUR, KGM, LTR, MTR, …). The Facturae parser reads ReceiverTransactionReference, ReceiverContractReference and RelatedInvoice back, so these round-trip.
EN 16931 to KSeF FA(3)
target=ksef returns a KSeF FA(3) 1-0E document checked with the official FA(3) schema and its occurrence limits. It is not submitted to KSeF: submission needs the seller's KSeF authorisation, and the invoice counts as issued only with its KSeF number. The result carries the warning ksef_not_submitted.
FA(3) is issued by Polish taxpayers: the seller VAT identifier (BT-31) must be PL followed by a 10-digit NIP with a valid check digit, otherwise 422 unsupported_conversion. The Polish mandatory data comes from options:
{
"document": "<Invoice …>",
"target": "ksef",
"ksef": {
"annotations": { "cashAccounting": false, "splitPayment": false, "simplifiedTriangular": false, "marginScheme": false, "newMeansOfTransport": false },
"buyer": { "jst": false, "vatGroup": false }
}
}
| Option | FA(3) element | Notes |
|---|---|---|
annotations.cashAccounting |
P_16 | Required |
annotations.splitPayment |
P_18A | Required |
annotations.simplifiedTriangular |
P_23 | Required |
annotations.marginScheme, annotations.newMeansOfTransport |
PMarzy, NoweSrodkiTransportu | Required, must be false: margin schemes and new means of transport are not supported |
buyer.jst, buyer.vatGroup |
JST, GV | Required |
notSubjectToVat (np I / np II) |
P_12, P_13_8 / P_13_9 | Required when the invoice has VAT category O |
paymentDate |
Zaplacono, DataZaplaty | Required when the invoice is fully paid (BT-113 = BT-112) |
placeOfIssue |
P_1M | Optional |
Derived from the invoice: P_17 from type 389 (self-billing), P_18 from category AE (reverse charge), P_19 / P_19A from category E and its exemption reason. Annotations set to 1 read back as invoice notes and are not compared. Mapping: P_2 BT-1, P_1 BT-2, P_6 BT-72 or OkresFa BG-14, P_13_x / P_14_x per rate (23/22, 8/7, 5, 4/3; Z 0 KR, K 0 WDT, G 0 EX, E zw, AE oo), P_15 BT-112, FaWiersz per line (P_7 name, Indeks, GTIN, P_8A Polish unit abbreviation, P_8B, P_9A, P_10 BT-147, P_11, P_12), Platnosc (due date, means 10, 20, 30, 48, 68, accounts), WarunkiTransakcji (BT-12, BT-13), notes of the form key: value as DodatkowyOpis and the last other note as StopkaFaktury, a 10-digit KRS as BT-30. An invoice in another currency needs BT-6 = PLN and BT-111 (VAT in PLN; one taxable rate only). The KSeF parser reads WarunkiTransakcji back, so BT-12 / BT-13 round-trip.
Facturae and KSeF to EN 16931
These are national formats, not EN 16931 syntaxes. The mapping is deterministic; values EN 16931 needs that the source does not carry verbatim (for example the ES / PL VAT prefix, VAT categories, UN/ECE unit codes, totals) are listed in metadata.derivedValues. Data without an EN 16931 equivalent — IRPF and other withheld taxes, equivalence surcharge, FACe centres, the Facturae third-party issuer, the KSeF place of issue — makes the call fail with semantic_loss unless you pass allowDataLoss=true.
convert.sh
#!/usr/bin/env bash
# Convert an XRechnung UBL invoice to CII and save the result.
set -euo pipefail
curl -sS --fail-with-body "$EINV_BASE/v1/invoices/convert?target=cii&store=false" \
-H "Authorization: Bearer $EINV_KEY" \
-H "Content-Type: application/xml" \
-H "Idempotency-Key: convert-$(date +%s)" \
--data-binary @"${1:-invoice.xml}" \
| node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{const r=JSON.parse(s);require("fs").writeFileSync("invoice-cii.xml",r.document);console.log(r.validation.status, r.dataLoss.lossless ? "lossless" : "lossy")})'
How a conversion is checked
source → parser → EN 16931 model → target serializer → official validator → parser → compare
- The source must be valid. An invalid source returns
422 source_invalidwith its errors. - If the source contains data the model cannot hold, the call fails with
422 semantic_lossand lists the fields. - The output is validated with the official rules. If it does not pass, you get
422 conversion_output_invalid— never an invalid document. - The output is parsed again and compared field by field with the source model. Any difference fails with
semantic_loss.
Pass allowDataLoss=true to receive the document anyway when steps 2 or 4 report a loss; the loss is listed in dataLoss.
Known target-syntax limits
| Situation | Result |
|---|---|
| More than one preceding invoice reference (BG-3) to CII | semantic_loss — CII D16B holds one |
| CII line-level VAT exemption reason to UBL | semantic_loss — no EN 16931 term at line level |
| XRechnung Extension features (sub-lines, third-party payments) | semantic_loss |
| BT-110 missing in CII, converting to UBL | written as the sum of BT-117 (warnings[].derived = true) |
| Payment card to UBL | cbc:NetworkID is required by UBL and written as NA (warning) |
| More than one buyer identifier (BT-46) to UBL | semantic_loss — UBL allows one (UBL-SR-16) |
| Gross price without price discount to UBL | discount written as 0.00 (derived) |
| XRechnung identifier schemes XR01 / XR03 or CVD classification lists to Factur-X EXTENDED | conversion_output_invalid — not in the Factur-X EXTENDED code lists (FX-SCH-A-001145 / 001146) |
| CII without BT-110 to Factur-X EXTENDED | conversion_output_invalid — Factur-X rule BR-FXEXT-CO-15 |
| To Facturae: BT-7, BT-8, BT-10, BT-11, BT-14..BT-20, BT-21 subject codes, BT-111, BT-114, BG-10, BG-11, BG-24, deliver-to party and address | semantic_loss — no Facturae element |
| To Facturae: party identifiers (BT-29/46), legal registration, BT-32, BT-33, electronic addresses (BT-34/49), address lines 2 and 3 | semantic_loss |
| To Facturae: line object identifier, accounting reference, item description, buyer / standard identifiers, classification, origin, attributes, gross price and price discount, base quantity other than 1 | semantic_loss |
| To Facturae: allowance / charge base amount or reason code, VAT exemption reason code (BT-121), categories AE, K, G (Facturae has only exempt / not subject) | semantic_loss |
| To Facturae: payment means text, card, mandate and creditor id, account name, more than one account, payment means without a Facturae code (e.g. 58) or without a due date | semantic_loss |
| To Facturae: texts longer than the Facturae maximum (e.g. BT-12 / BT-13 / BT-155 over 20 characters, a contact over 40) | semantic_loss (shortened if the loss is accepted) |
| To Facturae: overseas post code and town | written together in PostCodeAndTown; compared as equal |
| To Facturae: 8-character BIC | written with branch code XXX (warning bic_branch_code); compared as equal |
| To Facturae: credit note (381), corrective invoice (384), other type codes than 380 / 389, invoice number over 20 characters | unsupported_conversion — Facturae corrective data (reason, method, tax period) is not in EN 16931 |
To Facturae: no street address, town, country or (without the option) province; no VAT identifier and no taxId |
target_data_required |
| To KSeF: seller without a Polish NIP, NIP with a wrong check digit, credit notes, corrective invoices, type codes other than 380 / 389 | unsupported_conversion |
| To KSeF: BT-7, BT-8, BT-10, BT-11, BT-14..BT-20, BG-3, BG-10, BG-11, BG-24, BG-20/21 document allowances and charges, BG-27/28 line allowances and charges, line notes, periods, order line and accounting references, BT-114, partial prepayment | semantic_loss — no FA(3) element |
| To KSeF: VAT rates without an FA(3) rate (e.g. 19 %), two rates in the same P_13_x field, BT-120 texts for K, G, AE, O (FA(3) states them by the rate code only), BT-121 | semantic_loss |
To KSeF: more than one note without the form key: value, trading names, electronic addresses, contact names, address line 3, subdivision, a second address line together with post code and town |
semantic_loss |
| To KSeF: foreign post code and town | written in AdresL2; compared as equal |
| To KSeF: invoice not in PLN without BT-6 = PLN and BT-111 | target_data_required |
Test coverage
Every conversion is tested against the official XRechnung 3.0.2 test suite in both directions: 79 of 86 instances convert losslessly; the remaining 7 are refused for one of the reasons above (5 Extension documents, one line-level VAT exemption reason, one document with two preceding invoices). The Peppol, FeRD ZUGFeRD, Facturae and KSeF samples are covered as well; see the changelog for the current numbers.
Factur-X EXTENDED output (XRechnung 3.0.2 suite, 86 documents, and the 25 FeRD ZUGFeRD 2.5.2 EN 16931 examples): 100 of 111 convert losslessly and pass the EXTENDED rules. 11 are refused: the 7 semantic_loss documents listed above, and 4 conversion_output_invalid (04.05a with XRechnung identifier schemes XR01 / XR03, the two CVD documents with XRechnung classification lists, 01.05 CII without BT-110). PDF/A-3 is checked by veraPDF where the PDF checker is enabled.
Facturae output (the same 111 documents plus the 8 Peppol BIS examples, 119 in total): none converts losslessly. Every one of these German and Peppol samples carries EN 16931 terms that Facturae has no element for — most often BT-10 buyer reference, BT-20 payment terms, BT-34 / BT-49 electronic addresses, note subject codes, party identifiers or gross prices — so they are refused with semantic_loss listing those terms. With allowDataLoss=true (and province / tax number options for these non-Spanish parties) 104 of 119 produce a Facturae file that passes the schema and calculation rules; 9 are refused as unsupported_conversion (types 384, 381, 575, 877) and 6 with target_data_required (no street address). Lossless round trips are tested with: the official Facturae samples invoice-face.xml and invoice-vat.xml converted to EN 16931 and back (both lossless, including the FACe centres passed as options), and the synthetic test cases with Spanish parties: standard rate, mixed rates, zero rated, exempt, allowance and charge, 60 lines and a natural person are lossless; reverse charge, intra-community supply and export are refused (semantic_loss, no Facturae category), the credit note with unsupported_conversion.
KSeF FA(3) output: none of the 119 official EN 16931 samples has a Polish seller, so all 119 are refused with unsupported_conversion. Lossless round trips are tested with the Ministry of Finance samples pdfgen-invoice.xml, invoice-template-fa-3.xml, -with-attachment and -with-custom-Subject2 converted to EN 16931 and back (4 of 4 lossless; the first hop to EN 16931 loses FA(3)-only data such as P_1M or Rozliczenie). The other MF templates do not reach EN 16931 (FA(2), a schema-invalid template, a Podmiot3 template that fails EN 16931 rules). Synthetic test cases with Polish parties, PLN and Polish rates: standard rate, mixed rates (23 / 8 %), zero rated, exempt and 60 lines are lossless; reverse charge, intra-community supply, export (reason texts) and allowance and charge (no document level allowances in FA(3)) are refused with semantic_loss, the credit note with unsupported_conversion.
E-Invoicing API