Skip to content

REST API for developers

Guide: understand and fix validation errors

Field errors and broken business rules, how to recognise them in the response and how to correct the request.

Contents

Goal and prerequisites

The API reports two kinds of errors:

  • Field errors: a field is missing or has an invalid value. The invoice is not created; the response is 400 with the fields.
  • Business rules: the fields are valid, but the invoice breaks a rule of EN 16931 or XRechnung, e.g. the seller has no VAT identifier. The validators report the rule ID, e.g. BR-CO-26.

Prerequisites: an API key in the environment variable API_KEY and invoice.json as in Guide: first e-invoice; curl and jq, or Python 3 with requests.

1. Read field errors

Example: the issue date in German notation and the first line without net price:

invoice.json
{
  "issue_date": "01.10.2026",
  "items": [
    {
      "line_id": "1",
      "name": "Beratungsleistung",
      "quantity": "8",
      "unit_code": "HUR",
      "tax_category": "S",
      "tax_rate": "19.00"
    }
  ]
}
curl (Shell)
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
Python (requests)
import json
import os

import requests

BASE_URL = "https://www.e-rechnungsfreund.de"
HEADERS = {"Authorization": f"Api-Key {os.environ['API_KEY']}"}

with open("invoice.json", encoding="utf-8") as f:
    invoice = json.load(f)

response = requests.post(f"{BASE_URL}/api/v1/invoices/", json=invoice, headers=HEADERS, timeout=30)
if response.status_code == 400:
    problem = response.json()  # RFC 7807
    for error in problem.get("validation_errors", []):
        # "field" is the path in the request body, e.g. items.0.net_price
        print(f'{error.get("field", "(whole request)")}: {error["message"]}')
else:
    response.raise_for_status()
Example response: POST /api/v1/invoices/ → 400 Bad Request
JSON
{
  "type": "https://www.e-rechnungsfreund.de/api/errors/validationerror",
  "title": "ValidationError",
  "status": 400,
  "detail": "Invalid input.",
  "errors": {
    "issue_date": [
      "Date has wrong format. Use one of these formats instead: YYYY-MM-DD."
    ],
    "items": {
      "0": {
        "net_price": [
          "This field is required."
        ]
      }
    }
  },
  "validation_errors": [
    {
      "field": "issue_date",
      "message": "Date has wrong format. Use one of these formats instead: YYYY-MM-DD."
    },
    {
      "field": "items.0.net_price",
      "message": "This field is required."
    }
  ]
}
  • validation_errors is a flat list: field is the path in the request body with dots and list indices (items.0.net_price = first line), message the reason. Use it to mark the field in your form.
  • errors contains the same messages, nested like the request body.
  • Show or log detail and message, but do not evaluate their text; it may change.

2. Check business rules

POST /api/v1/invoices/validate_draft/ takes the same data as creating an invoice, generates the XML, checks it and saves nothing. It counts towards no quota. Example: invoice.json without the VAT identifier of the seller:

invoice.json
{
  "seller": {
    "name": "Muster GmbH",
    "street": "Musterstraße 1",
    "postal_code": "10115",
    "city": "Berlin",
    "country_code": "DE",
    "contact_name": "Max Mustermann",
    "contact_phone": "+49 30 12345678",
    "contact_email": "rechnung@muster.example"
  }
}
curl (Shell)
curl -sS -X POST "https://www.e-rechnungsfreund.de/api/v1/invoices/validate_draft/" \
  -H "Authorization: Api-Key $API_KEY" \
  -H "Content-Type: application/json" \
  -d @invoice.json \
  | jq -r '[.kosit.errors[]?, .saxon.errors[]?] | map(.message? // .) | unique[]'
Python (requests)
import re

RULE_ID = re.compile(r"^\[([A-Za-z0-9-]+)\]")


def rule_errors(result):
    """Errors of all validators, one entry per rule: {rule ID: message}."""
    found = {}
    for validator in ("kosit", "saxon"):
        for error in (result.get(validator) or {}).get("errors", []):
            message = error["message"] if isinstance(error, dict) else str(error)
            match = RULE_ID.match(message)
            found.setdefault(match.group(1) if match else "?", message)
    return found


check = requests.post(f"{BASE_URL}/api/v1/invoices/validate_draft/", json=invoice, headers=HEADERS, timeout=120)
check.raise_for_status()  # 400 = field errors as in step 1
errors = rule_errors(check.json())
for rule_id, message in errors.items():
    print(rule_id, message)
Example response: POST /api/v1/invoices/validate_draft/ → 200 OK
JSON
{
  "kosit": {
    "is_valid": false,
    "applicable": true,
    "errors": [
      {
        "message": "[BR-S-02]-An Invoice that contains an Invoice line (BG-25) where the Invoiced item VAT category code (BT-151) is \"Standard rated\" shall contain the Seller VAT Identifier (BT-31), the Seller tax registration identifier (BT-32) and/or the Seller tax representative VAT identifier (BT-63).",
        "affected_codes": [
          "BG-25",
          "BT-151",
          "BT-31",
          "BT-32",
          "BT-63",
          "BR-S-02"
        ]
      },
      {
        "message": "[BR-CO-26]-In order for the buyer to automatically identify a supplier, the Seller identifier (BT-29), the Seller legal registration identifier (BT-30) and/or the Seller VAT identifier (BT-31) shall be present.",
        "affected_codes": [
          "BT-29",
          "BT-30",
          "BT-31",
          "BR-CO-26"
        ]
      }
    ],
    "warnings": [],
    "method": "daemon"
  },
  "saxon": {
    "is_valid": false,
    "errors": [
      {
        "message": "[BR-CO-26]-In order for the buyer to automatically identify a supplier, the Seller identifier (BT-29), the Seller legal registration identifier (BT-30) and/or the Seller VAT identifier (BT-31) shall be present.",
        "affected_codes": [
          "BT-29",
          "BT-30",
          "BT-31",
          "BR-CO-26"
        ]
      },
      {
        "message": "[BR-S-02]-An Invoice that contains an Invoice line (BG-25) where the Invoiced item VAT category code (BT-151) is \"Standard rated\" shall contain the Seller VAT Identifier (BT-31), the Seller tax registration identifier (BT-32) and/or the Seller tax representative VAT identifier (BT-63).",
        "affected_codes": [
          "BG-25",
          "BT-151",
          "BT-31",
          "BT-32",
          "BT-63",
          "BR-S-02"
        ]
      }
    ],
    "warnings": [],
    "method": "saxon (xslt 2.0)"
  }
}
  • The status is 200 even if rules are broken; is_valid of each validator is the result. kosit is decisive; saxon checks the EN 16931 rules once more and is missing for XRechnung.
  • Each message starts with the rule ID in square brackets. Several validators can report the same rule; group the messages by rule ID.
  • affected_codes names the business terms (BT/BG numbers) concerned, e.g. BT-31 = seller VAT identifier.

The same check runs when you create the file with POST /api/v1/invoices/{invoice_id}/generate_zugferd_pdf/. If it finds errors there, the response is 400 with the messages in details:

Example response: POST /api/v1/invoices/{invoice_id}/generate_zugferd_pdf/ → 400 Bad Request
JSON
{
  "type": "https://www.e-rechnungsfreund.de/api/errors/badrequest",
  "title": "BadRequest",
  "status": 400,
  "detail": "Validation failed",
  "details": [
    {
      "message": "[BR-S-02]-An Invoice that contains an Invoice line (BG-25) where the Invoiced item VAT category code (BT-151) is \"Standard rated\" shall contain the Seller VAT Identifier (BT-31), the Seller tax registration identifier (BT-32) and/or the Seller tax representative VAT identifier (BT-63).",
      "affected_codes": [
        "BG-25",
        "BT-151",
        "BT-31",
        "BT-32",
        "BT-63",
        "BR-S-02"
      ]
    },
    {
      "message": "[BR-CO-26]-In order for the buyer to automatically identify a supplier, the Seller identifier (BT-29), the Seller legal registration identifier (BT-30) and/or the Seller VAT identifier (BT-31) shall be present.",
      "affected_codes": [
        "BT-29",
        "BT-30",
        "BT-31",
        "BR-CO-26"
      ]
    }
  ]
}

3. Look up the rule

GET /api/v1/validation-rules/BR-CO-26/ explains a rule: meaning, typical causes, how to fix it and the link to the rule page. It counts towards no quota. language (de or en) selects the language. If no explanation is published for a rule, explanation is null and the response contains only the official messages.

curl (Shell)
curl -sS "https://www.e-rechnungsfreund.de/api/v1/validation-rules/BR-CO-26/?language=en" \
  -H "Authorization: Api-Key $API_KEY"
Python (requests)
for rule_id in errors:
    if rule_id == "?":
        continue  # message without rule ID
    rule = requests.get(
        f"{BASE_URL}/api/v1/validation-rules/{rule_id}/",
        params={"language": "en"},
        headers=HEADERS,
        timeout=30,
    )
    if rule.status_code == 404:
        continue  # unknown rule ID
    rule.raise_for_status()
    data = rule.json()
    explanation = data["explanation"] or {}  # null if no explanation is published
    print(rule_id, explanation.get("title", ""), data["rule_url"])
    for step in explanation.get("fix_general", []):
        print("  -", step)
Example response: GET /api/v1/validation-rules/BR-CO-26/ → 200 OK

Excerpt: the explanation is shortened; the response can also contain fix_in_app and examples of wrong and correct XML.

JSON
{
  "rule_id": "BR-CO-26",
  "found": true,
  "severity": "error",
  "affected_terms": [
    "BT-29",
    "BT-30",
    "BT-31"
  ],
  "rule_url": "https://www.e-rechnungsfreund.de/en/validation-rules/br-co-26/",
  "official_messages": [
    {
      "source": "EN 16931 (CII)",
      "language": "en",
      "message": "In order for the buyer to automatically identify a supplier, the Seller identifier (BT-29), the Seller legal registration identifier (BT-30) and/or the Seller VAT identifier (BT-31) shall be present."
    }
  ],
  "explanation": {
    "language": "en",
    "title": "Seller identification is missing (BT-29, BT-30 or BT-31)",
    "summary": "In order for the buyer to automatically identify the supplier, the invoice shall contain at least one of the following for the seller: seller identifier (BT-29), seller legal registration identifier (BT-30) or seller VAT identifier (BT-31). None of them is present.",
    "causes": [
      "The fields for identifier, registration number and VAT identifier of the seller were left empty."
    ],
    "fix_general": [
      "State at least one of: VAT identifier (BT-31), trade register or other legal registration number (BT-30), or a seller identifier such as a GLN (BT-29)."
    ]
  }
}

All rules can also be found in the validation rules. For existing files, POST /api/v1/validate/ with include_explanations=true returns the explanations together with the result.

4. Correct and send again

Here the seller needs a VAT identifier: add "vat_id" to seller, check again and then create the invoice.

curl (Shell)
# after adding "vat_id" to "seller" in invoice.json
curl -sS -X POST "https://www.e-rechnungsfreund.de/api/v1/invoices/validate_draft/" \
  -H "Authorization: Api-Key $API_KEY" \
  -H "Content-Type: application/json" \
  -d @invoice.json \
  | jq '{kosit: .kosit.is_valid, saxon: .saxon.is_valid}'

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
Python (requests)
invoice["seller"]["vat_id"] = "DE123456789"

check = requests.post(f"{BASE_URL}/api/v1/invoices/validate_draft/", json=invoice, headers=HEADERS, timeout=120)
check.raise_for_status()
if rule_errors(check.json()):
    raise SystemExit("still invalid")

created = requests.post(f"{BASE_URL}/api/v1/invoices/", json=invoice, headers=HEADERS, timeout=30)
created.raise_for_status()
print("created", created.json()["id"])
Example response: POST /api/v1/invoices/validate_draft/ → 200 OK

Excerpt: one result per validator.

JSON
{
  "kosit": {
    "is_valid": true,
    "errors": [],
    "warnings": [],
    "method": "daemon",
    "applicable": true
  },
  "saxon": {
    "is_valid": true,
    "errors": [],
    "warnings": [],
    "method": "saxon (xslt 2.0)"
  }
}

Complete script on GitHub: check_invoice.sh, check_invoice.py

Next steps