REST API for developers
Guide: your first e-invoice
From the API key to the ZUGFeRD PDF and the XRechnung XML, with code and the expected response for each step.
Contents
Goal and prerequisites
At the end, you have created an invoice via the API and saved it as a ZUGFeRD PDF and as an XRechnung XML.
- An account with API access. All plans include the API within their limits; see Plans and API access.
- An API key (step 1).
- curl and jq, or Python 3 with the package
requests(pip install requests).
1. Set the API key
Create a key in your account under API keys. It is shown only once; copy it then. Keep it out of the source code: the examples read it from the environment variable API_KEY.
read -rs API_KEY && export API_KEY # paste the key; it does not end up in the shell history
curl -sS "https://www.e-rechnungsfreund.de/api/v1/account/" -H "Authorization: Api-Key $API_KEY" -o /dev/null -w "%{http_code}\n"
# 200 = key accepted, 401 = key missing, invalid, expired or revoked
import os
import requests
BASE_URL = "https://www.e-rechnungsfreund.de"
HEADERS = {"Authorization": f"Api-Key {os.environ['API_KEY']}"}
response = requests.get(f"{BASE_URL}/api/v1/account/", headers=HEADERS, timeout=30)
print(response.status_code) # 200 = key accepted, 401 = key missing, invalid, expired or revoked
Expected result: 200. With 401, check the key and the header.
2. Check the account
GET /api/v1/account/ shows the plan, the permissions and the remaining quotas. It counts towards no quota. permissions.api_access must be true for creating invoices.
curl -sS "https://www.e-rechnungsfreund.de/api/v1/account/" \
-H "Authorization: Api-Key $API_KEY"
account = requests.get(f"{BASE_URL}/api/v1/account/", headers=HEADERS, timeout=30)
account.raise_for_status()
data = account.json()
if not data["permissions"]["api_access"]:
raise SystemExit("This account can only check and read via the API.")
invoices = data["quotas"]["invoices"]
print(f"{invoices['remaining']} of {invoices['limit']} invoices left until {invoices['reset_date']}")
Example response: GET /api/v1/account/ → 200 OK
{
"plan": {
"code": "free",
"name": "Free"
},
"permissions": {
"api_access": true,
"api_validation_access": true,
"tax_advisor_export": false,
"invoice_emails": true
},
"quotas": {
"invoices": {
"used": 1,
"limit": 5,
"remaining": 4,
"reset_date": "2027-01-01"
},
"validations": {
"used": 3,
"limit": 30,
"remaining": 27,
"reset_date": "2027-01-01"
},
"party_templates": {
"used": 1,
"limit": 3,
"remaining": 2,
"reset_date": null
}
},
"party_templates": {
"seller": 1,
"buyer": 0,
"has_seller_template": true
}
}
3. Create the invoice
Save the invoice data as invoice.json and send it to POST /api/v1/invoices/. The response contains the id of the invoice and the calculated totals. Each invoice counts towards the invoices per month of your plan.
{
"invoice_number": "RE-2026-001",
"issue_date": "2026-10-01",
"delivery_date": "2026-10-01",
"type_code": "380",
"currency_code": "EUR",
"payment_terms": "Zahlbar innerhalb von 14 Tagen ohne Abzug",
"seller": {
"name": "Muster GmbH",
"street": "Musterstraße 1",
"postal_code": "10115",
"city": "Berlin",
"country_code": "DE",
"vat_id": "DE123456789",
"contact_name": "Max Mustermann",
"contact_phone": "+49 30 12345678",
"contact_email": "rechnung@muster.example"
},
"buyer": {
"name": "Käufer AG",
"street": "Käuferstraße 5",
"postal_code": "80331",
"city": "München",
"country_code": "DE",
"vat_id": "DE987654321"
},
"items": [
{
"line_id": "1",
"name": "Beratungsleistung",
"quantity": "8",
"unit_code": "HUR",
"net_price": "95.00",
"tax_category": "S",
"tax_rate": "19.00"
}
],
"tax_breakdowns": [
{
"tax_category": "S",
"tax_rate": "19.00",
"basis_amount": "760.00",
"tax_amount": "144.40"
}
]
}
INVOICE_ID=$(curl -sS -X POST "https://www.e-rechnungsfreund.de/api/v1/invoices/" \
-H "Authorization: Api-Key $API_KEY" \
-H "Content-Type: application/json" \
-d @invoice.json | jq -r .id)
echo "$INVOICE_ID"
import json
with open("invoice.json", encoding="utf-8") as f:
invoice = json.load(f)
created = requests.post(f"{BASE_URL}/api/v1/invoices/", json=invoice, headers=HEADERS, timeout=30)
if created.status_code == 400:
raise SystemExit(created.json()["validation_errors"]) # see the guide on fixing errors
created.raise_for_status()
invoice_id = created.json()["id"]
Example response: POST /api/v1/invoices/ → 201 Created
Excerpt: the response contains all fields of the invoice, including the calculated totals.
{
"id": "3ff6fce7-0c0f-4726-8288-92947decc8aa",
"is_xrechnung": false,
"profile": "EN16931",
"invoice_number": "RE-2026-001",
"issue_date": "2026-10-01",
"type_code": "380",
"currency_code": "EUR",
"line_total_amount": "760.0000",
"tax_basis_total_amount": "760.0000",
"tax_total_amount": "144.4000",
"grand_total_amount": "904.4000",
"due_payable_amount": "904.4000",
"is_paid": false,
"export_status": "not_generated",
"created_at": "2026-10-01T09:30:00.000000Z",
"items": [
{
"id": "8be0e456-ae96-4a52-9139-f5359580fec3",
"line_id": "1",
"name": "Beratungsleistung",
"quantity": "8.0000",
"unit_code": "HUR",
"net_price": "95.0000",
"line_total_amount": "760.0000",
"tax_rate": "19.00",
"tax_category": "S"
}
]
}
With 400, a field is missing or invalid; Guide: fix errors shows how to read the answer.
4. Download the ZUGFeRD PDF
POST /api/v1/invoices/{invoice_id}/generate_zugferd_pdf/ creates the ZUGFeRD PDF (PDF/A-3 with embedded XML) and checks it. The response is the file itself. If the check finds errors, you receive 400 with the messages in details instead of a file.
curl -sS -X POST "https://www.e-rechnungsfreund.de/api/v1/invoices/$INVOICE_ID/generate_zugferd_pdf/" \
-H "Authorization: Api-Key $API_KEY" \
-o invoice.pdf -w "%{http_code}\n"
pdf = requests.post(
f"{BASE_URL}/api/v1/invoices/{invoice_id}/generate_zugferd_pdf/",
headers=HEADERS,
timeout=120,
)
if pdf.status_code == 400:
raise SystemExit(pdf.json()) # "details" lists the messages of the check
pdf.raise_for_status()
with open("invoice.pdf", "wb") as f:
f.write(pdf.content)
Example response: POST /api/v1/invoices/{invoice_id}/generate_zugferd_pdf/ → 200 OK
HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="ZUGFeRD_RE-2026-001.pdf"
The file is stored with the invoice; GET /api/v1/invoices/{invoice_id}/download/ downloads it again without creating it anew.
5. Download the XRechnung XML
For an XRechnung, e.g. for public authorities, create the invoice with "profile": "XRECHNUNG", the Leitweg-ID of the authority in buyer_reference (here the test value 04011000-12345-03), the electronic addresses of seller and buyer and the payment means:
{
"invoice_number": "RE-2026-002",
"issue_date": "2026-10-01",
"delivery_date": "2026-10-01",
"type_code": "380",
"currency_code": "EUR",
"payment_terms": "Zahlbar innerhalb von 14 Tagen ohne Abzug",
"profile": "XRECHNUNG",
"specification_identifier": "urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0",
"business_process_type": "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0",
"buyer_reference": "04011000-12345-03",
"seller": {
"name": "Muster GmbH",
"street": "Musterstraße 1",
"postal_code": "10115",
"city": "Berlin",
"country_code": "DE",
"vat_id": "DE123456789",
"contact_name": "Max Mustermann",
"contact_phone": "+49 30 12345678",
"contact_email": "rechnung@muster.example",
"electronic_address": "rechnung@muster.example",
"electronic_address_scheme": "EM"
},
"buyer": {
"name": "Stadtverwaltung Musterstadt",
"street": "Rathausplatz 1",
"postal_code": "80331",
"city": "München",
"country_code": "DE",
"electronic_address": "991-33333TEST-33",
"electronic_address_scheme": "0204"
},
"payment_means": [
{
"type_code": "58",
"iban": "DE02120300000000202051",
"account_name": "Muster GmbH"
}
],
"items": [
{
"line_id": "1",
"name": "Beratungsleistung",
"quantity": "8",
"unit_code": "HUR",
"net_price": "95.00",
"tax_category": "S",
"tax_rate": "19.00"
}
],
"tax_breakdowns": [
{
"tax_category": "S",
"tax_rate": "19.00",
"basis_amount": "760.00",
"tax_amount": "144.40"
}
]
}
Then POST /api/v1/invoices/{invoice_id}/generate_xrechnung/ returns the XRechnung as XML. An XRechnung has no PDF; generate_zugferd_pdf answers 400 for it.
XRECHNUNG_ID=$(curl -sS -X POST "https://www.e-rechnungsfreund.de/api/v1/invoices/" \
-H "Authorization: Api-Key $API_KEY" \
-H "Content-Type: application/json" \
-d @xrechnung-invoice.json | jq -r .id)
curl -sS -X POST "https://www.e-rechnungsfreund.de/api/v1/invoices/$XRECHNUNG_ID/generate_xrechnung/" \
-H "Authorization: Api-Key $API_KEY" \
-o invoice.xml -w "%{http_code}\n"
with open("xrechnung-invoice.json", encoding="utf-8") as f:
xrechnung = json.load(f)
created = requests.post(f"{BASE_URL}/api/v1/invoices/", json=xrechnung, headers=HEADERS, timeout=30)
created.raise_for_status()
xrechnung_id = created.json()["id"]
xml = requests.post(
f"{BASE_URL}/api/v1/invoices/{xrechnung_id}/generate_xrechnung/",
headers=HEADERS,
timeout=120,
)
xml.raise_for_status()
with open("invoice.xml", "wb") as f:
f.write(xml.content)
Example response: POST /api/v1/invoices/{invoice_id}/generate_xrechnung/ → 200 OK
HTTP/1.1 200 OK
Content-Type: application/xml; charset=utf-8
Content-Disposition: attachment; filename="XRechnung_RE-2026-002.xml"
Complete script on GitHub:
first_invoice.sh, first_invoice.py
Next steps
- Check an existing file or read a received e-invoice: Quickstart.
- Understand and fix validation errors: Guide: fix errors.
- Be notified when an invoice is paid: Guide: webhooks.
- Mark the invoice as issued and record the payment: Guide: invoice lifecycle.
- Errors, rate limits, quotas and data formats in detail: Implementation details.
- All fields of an invoice: Open API documentation