Skip to content
CastPDF
E-invoicing API

E-invoicing API: one JSON invoice, every EU format

An e-invoicing API turns the invoice data you already have into a structured e-invoice. Send one JSON invoice to CastPDF and get a ZUGFeRD or Factur-X PDF/A-3 with the XML inside, or an XRechnung XML for German public buyers. The totals follow the EN 16931 rules, so the PDF and the XML always agree.

  • Updated
  • 7 minute read
  • 100 free PDFs a month
  1. A PDF/A-3b fileThe archive format that allows an attached file. The veraPDF checker found our samples clean.
  2. The page people readRendered from the built-in invoice template, or from your own.
  3. The XML software readsfactur-x.xml in CII syntax, attached as the alternative form of the invoice.
  4. One set of totalsComputed once with exact decimals, printed on the page and written in the XML.
A hybrid e-invoice: a PDF/A-3b page that people read, with the invoice XML attached inside the file for software to read. Both show the same totals.

What an e-invoice is

In short

An e-invoice carries the invoice as structured data that software can book. A plain PDF is a picture of an invoice; an e-invoice is the invoice itself.

For years an emailed PDF was a perfectly good invoice. The buyer read it, typed the numbers into their accounting system and paid. EU law now calls that a paper-like format. An electronic invoice in the legal sense is a file in a structured format that follows the European standard EN 16931.

There are two ways to deliver that structure. The first is the XML on its own, which is what XRechnung is. The second is a hybrid: a normal PDF that people read, with the same invoice attached inside it as XML. ZUGFeRD in Germany and Factur-X in France are the hybrid formats, and since ZUGFeRD 2.1 they are technically the same file.

  1. Your billingan invoice is final
  2. e_invoice JSONparties, lines, VAT
  3. CastPDFchecks and computes
  4. PDF/A-3 + XMLor the XRechnung XML
  5. Your customerbooks it without typing
POST /v1/pdfone request, one document

In a hybrid invoice the XML is the part that counts legally. The German tax authority says so explicitly. That is why the numbers on the page and in the XML must never differ, and why CastPDF builds both from one calculation.

ZUGFeRD, XRechnung or Factur-X?

In short

Selling to German businesses: ZUGFeRD. Selling to German public buyers: XRechnung. Selling in France: Factur-X. All three come from the same request.

The three formats side by side
ZUGFeRDXRechnungFactur-X
Where it is usedGermany, business to businessGermany, public buyers (and many businesses)France, and German readers of ZUGFeRD
What the file isPDF/A-3 with factur-x.xml insideXML only (CII or UBL syntax)PDF/A-3 with factur-x.xml inside
People can read itYes, it is a PDFOnly with a viewer, or a readable copyYes, it is a PDF
Extra data requiredNone beyond EN 16931Leitweg-ID, seller contact, electronic addressesNone beyond EN 16931
The standard to sendzugferdxrechnung-cii or xrechnung-ublfactur-x

The usual question is ZUGFeRD vs XRechnung. Public authorities in Germany expect XRechnung, usually through a portal, and tell you whether they take CII or UBL. Businesses mostly prefer ZUGFeRD, because their staff can still open and read the PDF. Both count as e-invoices under the German rules. Our ZUGFeRD page and XRechnung page go deeper into each one.

Profiles: how much data the XML carries

Factur-X and ZUGFeRD profiles
ProfileInvoice linesA full e-invoice in GermanyThe `profile` to send
MINIMUMNo, header and totals onlyNominimum
BASIC WLNo, header and totals onlyNobasic-wl
BASICYesYesbasic
EN 16931 (once called COMFORT)Yes, the full European standardYesen16931 (the default)
EXTENDEDYes, with extra fieldsYesextended
XRECHNUNG (ZUGFeRD only)Yes, with the XRechnung rulesYesxrechnung

Use en16931 unless your customer asks for something else. It carries the whole invoice, and it is what most receiving software expects. The two smallest profiles carry no lines, so the German rules do not accept them as invoices.

The German e-invoicing mandate, 2025 to 2028

In short

Every German business must already be able to receive e-invoices. Sending them becomes mandatory in two steps: 2027 for larger businesses, 2028 for everyone.

  1. 1 January 2025In forceEveryone must receiveEvery business in Germany must be able to receive and process e-invoices from other businesses.
  2. Until 31 December 2026NowTransition for sendersYou may still send paper, or with the buyer’s consent a plain PDF or another electronic format.
  3. 1 January 2027ComingLarger businesses must sendBusinesses with more than EUR 800,000 turnover in the previous year must issue e-invoices.
  4. 1 January 2028ComingEveryone must sendThe transition ends for all businesses. Domestic B2B invoices must be e-invoices.

The rules come from the Growth Opportunities Act (Wachstumschancengesetz) and the Federal Ministry of Finance letters that explain it. Invoices to consumers are out of scope, and so are small invoices up to EUR 250 and travel tickets. The ministry’s FAQ has the details in German.

  • XRechnung counts as an e-invoice.
  • ZUGFeRD from version 2.0.1 counts, except the MINIMUM and BASIC WL profiles.
  • A plain PDF is no longer an e-invoice, even if you send it by email.
  • In a hybrid ZUGFeRD file, the XML wins if it differs from the page.

Public buyers are a separate, older story. Suppliers to the federal administration have had to send e-invoices since November 2020, and XRechnung is the format those buyers expect. Several federal states have similar rules. Each public buyer gives you a Leitweg-ID, which goes into the invoice as the buyer reference.

E-invoicing in France: Factur-X and the 2026 reform

In short

France is moving every domestic B2B invoice onto approved platforms. Factur-X is one of the formats those platforms accept, and CastPDF creates it.

France chose a different model from Germany. Invoices between French businesses will travel through approved platforms (plateformes agréées), which also report the data to the tax administration. The French finance laws set two dates, and the first one has already passed.

The French reform dates
FromReceiving e-invoicesSending e-invoices
1 September 2026Every businessLarge and mid-sized businesses
1 September 2027Every businessSmall and micro businesses too

The platforms accept three base formats: Factur-X, CII and UBL. Factur-X is the popular one, because it stays a readable PDF. CastPDF makes the Factur-X file; your approved platform carries it to the buyer and reports it. CastPDF is not a platform and does not transmit invoices. Ask your platform which Factur-X profile it wants, and check the current dates with it, because French deadlines have moved before.

Our Factur-X page shows a French invoice request and the fields French invoices need.

One request, from JSON to e-invoice

Put the invoice in e_invoice on the normal POST /v1/pdf request. You need no template: the built-in invoice template renders the page. Change standard to switch formats; the invoice stays the same.

{
  "e_invoice": {
    "standard": "zugferd",
    "profile": "en16931",
    "invoice": {
      "number": "RE-2026-0815",
      "issue_date": "2026-10-10",
      "currency": "EUR",
      "seller": {
        "name": "Lindqvist Software GmbH",
        "vat_id": "DE123456789",
        "address": { "line1": "Kastanienallee 12", "city": "Berlin", "postal_code": "10435", "country_code": "DE" }
      },
      "buyer": {
        "name": "Brightwater Kaffee GmbH",
        "address": { "city": "Hamburg", "postal_code": "20457", "country_code": "DE" }
      },
      "payment": { "iban": "DE89370400440532013000", "due_date": "2026-11-09" },
      "lines": [
        { "name": "Software licence", "quantity": 1, "unit_price": "4800.00", "vat": { "category": "S", "rate": 19 } },
        { "name": "Printed handbook", "quantity": 3, "unit_price": "24.90", "vat": { "category": "S", "rate": 7 } }
      ]
    }
  }
}
curl https://api.castpdf.com/v1/pdf \
  -H "Authorization: Bearer $CASTPDF_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: invoice-RE-2026-0815" \
  -d @RE-2026-0815.json \
  -o RE-2026-0815.pdf
import { readFile, writeFile } from 'node:fs/promises';

const body = await readFile('RE-2026-0815.json', 'utf8');
const res = await fetch('https://api.castpdf.com/v1/pdf', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.CASTPDF_API_KEY}`,
    'Content-Type': 'application/json',
    'Idempotency-Key': 'invoice-RE-2026-0815',
  },
  body,
});
if (!res.ok) {
  const { error } = await res.json();
  // invalid_e_invoice lists every problem in error.details.issues
  throw new Error(`${error.code}: ${error.message}`);
}
await writeFile('RE-2026-0815.pdf', Buffer.from(await res.arrayBuffer()));
import json
import os

import requests

with open("RE-2026-0815.json", encoding="utf-8") as f:
    body = json.load(f)

res = requests.post(
    "https://api.castpdf.com/v1/pdf",
    headers={
        "Authorization": f"Bearer {os.environ['CASTPDF_API_KEY']}",
        "Idempotency-Key": "invoice-RE-2026-0815",
    },
    json=body,
    timeout=60,
)
if not res.ok:
    error = res.json()["error"]
    raise RuntimeError(f"{error['code']}: {error['message']}")
with open("RE-2026-0815.pdf", "wb") as f:
    f.write(res.content)
HTTP/1.1 200 OK
content-type: application/pdf
content-disposition: attachment; filename="RE-2026-0815.pdf"
x-e-invoice: zugferd/en16931
x-pages: 1

Change standard to xrechnung-ubl and the same request returns the XRechnung XML instead, once the invoice has the extra XRechnung fields. The API reference lists every field, and the ZUGFeRD and XRechnung guide covers credit notes, reverse charge and exempt sales.

Totals computed once, printed twice

In short

The most common reason an e-invoice is rejected is a total that is a cent off. We compute every total ourselves, with the rules the validators use.

  • Each line is quantity times net price, rounded to cents, then line discounts and charges.
  • VAT is computed once per category and rate, not per line, and rounded half away from zero.
  • Exact decimals throughout: no floating point, so 0.1 plus 0.2 is 0.30.
  • Send your own totals if you like; any field that differs is reported with our value.
  • Reverse charge, intra-EU supplies and exports get the standard exemption text and code.

Many billing systems round VAT on every line. EN 16931 rounds it once per rate, which can differ by a cent. If you send your totals, the API tells you exactly which one is off and why, before anything is rendered or counted.

What we validated, and how

In short

Every claim here names the tool, the version and the result. No authority has reviewed CastPDF, and we do not claim one has.

Validation of CastPDF e-invoices
CheckToolResult
XML structure, every profileThe official XSD schemas, in our test suiteEvery generated XML passes
Business rulesOfficial Schematron: CEN EN 16931 1.3.16, Factur-X 1.09, KoSIT XRechnung 3.0.2No failed rule in our test suite
PDF/A-3bveraPDF 1.30.3, run on 10 October 202616 of 16 sample PDFs compliant, 0 failed checks
XRechnung and EN 16931KoSIT validator 1.6.3 with the XRechnung 3.0.2 configurationAll 14 files accepted, 0 failed assertions

The samples cover six invoice shapes: two VAT rates with discounts and charges, reverse charge, an exempt sale, a credit note, an intra-EU supply and a 40-line rounding test. They also cover logos, test watermarks and right-to-left and Chinese text in the PDF.

What these checks do not cover

The KoSIT configuration has no scenario for the Factur-X MINIMUM, BASIC and EXTENDED profiles; the Factur-X Schematron in our tests covers those. veraPDF checks PDF/A, not the match between the PDF metadata and the XML. Your receiver may have its own extra rules, so send them a test invoice first.

Check or create an e-invoice for free

Two free tools use the same engine as the API, without an account. The e-invoice validator reads an XRechnung XML or a ZUGFeRD or Factur-X PDF and checks the fields and the totals. The e-invoice generator turns a short form into a ZUGFeRD PDF or an XRechnung XML.

Both are rate limited and stamp a small CastPDF footer on generated PDFs. When you need e-invoices from your own system, the API does the same work without the footer on paid plans.

What an e-invoice costs

An e-invoice counts on your plan exactly like any other PDF. The Free plan includes 100 documents a month, and paid plans start at $19 a month for 2,500. Test keys make unlimited watermarked e-invoices while you build, and a request that fails validation is never counted. See pricing for every plan.

Common questions

Is a ZUGFeRD PDF a valid e-invoice in Germany?

Yes, from ZUGFeRD 2.0.1 on and with the BASIC profile or higher. CastPDF writes EN 16931 by default. The MINIMUM and BASIC WL profiles carry no invoice lines and do not count as e-invoices.

Do I need XRechnung or ZUGFeRD?

Public buyers usually require XRechnung, often through their portal. Business customers can take either, and most prefer ZUGFeRD because it stays a readable PDF. Ask your customer if you are unsure.

Does CastPDF send e-invoices over Peppol or a French platform?

No. CastPDF creates the e-invoice file. You send it through the channel your customer or the law requires: email, a public portal, Peppol or a French approved platform.

Who checked that CastPDF e-invoices are correct?

We did, with the reference tools. The veraPDF checker found our sample PDFs compliant with PDF/A-3b, and the KoSIT validator accepted our XRechnung and EN 16931 files. No authority has reviewed CastPDF itself.

Can an e-invoice use my own layout?

Yes. Send template_id with e_invoice. Your template receives the invoice with every amount computed, so your page shows the same numbers as the XML.

What happens if my invoice data is incomplete?

The API answers with invalid_e_invoice and lists every problem with its field path, all at once. Nothing is rendered or counted, so you fix the data and send it again.

Does an e-invoice cost extra?

No. It counts as one document on your plan, the same as any PDF. Test keys make watermarked e-invoices for free while you build.

Everything on the E-invoicing API

Every guide, template and example that builds on this page. Each one answers a narrower question in more depth.

Use cases

Guides

Free tools

Your first PDF in five minutes.

Pick a template, create a free test key and send one request. 100 PDFs a month are free, and you never need a card to start.