Skip to content

REST API for developers

Guide: outgoing invoice lifecycle

From the created invoice to the recorded payment: status, payments and lists of open and paid invoices.

Contents

Goal and prerequisites

At the end, your invoice is marked as issued, the payment is recorded and you can list open and paid invoices from your own software.

Each invoice has a managed invoice under /api/v1/managed-invoices/ with its own id (a number). It holds the lifecycle: status, payments, open amount and the audit log. The invoice data stays under /api/v1/invoices/.

  • 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 the package requests.
  • Setting the status, recording payments and querying count towards no quota.

1. Create and export the invoice

Create the invoice and the ZUGFeRD PDF as in the first guide. Keep the id of the invoice.

curl (Shell)
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)

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"
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)

created = requests.post(f"{BASE_URL}/api/v1/invoices/", json=invoice, headers=HEADERS, timeout=30)
created.raise_for_status()
invoice_id = created.json()["id"]

pdf = requests.post(
    f"{BASE_URL}/api/v1/invoices/{invoice_id}/generate_zugferd_pdf/",
    headers=HEADERS,
    timeout=120,
)
pdf.raise_for_status()  # 400 = the check found errors, see "details"
with open("invoice.pdf", "wb") as f:
    f.write(pdf.content)

Expected result: 201 for the invoice and 200 with the PDF.

2. Find the managed invoice

The filter invoice_id returns the managed invoice of your invoice. Its id is needed for all further steps.

curl (Shell)
MANAGED_ID=$(curl -sS "https://www.e-rechnungsfreund.de/api/v1/managed-invoices/?invoice_id=$INVOICE_ID" \
  -H "Authorization: Api-Key $API_KEY" \
  | jq -r '.[0].id')
Python (requests)
found = requests.get(
    f"{BASE_URL}/api/v1/managed-invoices/",
    params={"invoice_id": invoice_id},
    headers=HEADERS,
    timeout=30,
)
found.raise_for_status()
managed = found.json()[0]
managed_id = managed["id"]
print(managed_id, managed["status"], managed["export_status"])
Example response: GET /api/v1/managed-invoices/?invoice_id=… → 200 OK
JSON
[
  {
    "id": 1234,
    "invoice_id": "3ff6fce7-0c0f-4726-8288-92947decc8aa",
    "invoice_number": "RE-2026-001",
    "buyer_name": "Käufer AG",
    "seller_name": "Muster GmbH",
    "direction": "outgoing",
    "issue_date": "2026-10-01",
    "payment_due_date": null,
    "due_payable_amount": "904.4000",
    "paid_amount": "0.00",
    "open_amount": "904.40",
    "status": "draft",
    "export_status": "ready",
    "source_file": null,
    "is_overdue": false,
    "updated_at": "2026-10-01T09:31:00.000000Z",
    "paid_at": null
  }
]
  • status is still draft: creating the file does not issue the invoice.
  • export_status ready means: the checked file is stored.

3. Set the status

When you have sent the invoice to your customer, set it to issued with POST /api/v1/managed-invoices/{id}/set-status/. The response is the managed invoice after the change, including the new entry in audit_logs.

curl (Shell)
curl -sS -X POST "https://www.e-rechnungsfreund.de/api/v1/managed-invoices/$MANAGED_ID/set-status/" \
  -H "Authorization: Api-Key $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"status": "issued"}' | jq '{status, issued_at}'
Python (requests)
issued = requests.post(
    f"{BASE_URL}/api/v1/managed-invoices/{managed_id}/set-status/",
    json={"status": "issued"},
    headers=HEADERS,
    timeout=30,
)
if issued.status_code == 400:
    raise SystemExit(issued.json()["validation_errors"])  # e.g. transition not allowed
issued.raise_for_status()
print(issued.json()["status"])
Example response: POST /api/v1/managed-invoices/{id}/set-status/ → 200 OK

Excerpt: the response contains all fields of the managed invoice.

JSON
{
  "id": 1234,
  "invoice_number": "RE-2026-001",
  "status": "issued",
  "issued_at": "2026-10-01T09:32:00.000000Z",
  "paid_at": null,
  "audit_logs": [
    {
      "id": 1,
      "action": "status_changed",
      "actor_display": "Max Mustermann",
      "old_value": {
        "status": "draft"
      },
      "new_value": {
        "status": "issued"
      },
      "created_at": "2026-10-01T09:32:00.000000Z"
    }
  ]
}

Allowed changes of an outgoing invoice:

StatusPossible next status
draftissued, cancelled
issuedpartially_paid, overdue, cancelled
partially_paidoverdue, cancelled
overduepartially_paid, cancelled

paid cannot be set: it follows from the recorded payments. Any other change that is not allowed gives 400:

Example response: POST /api/v1/managed-invoices/{id}/set-status/ → 400 Bad Request
JSON
{
  "type": "https://www.e-rechnungsfreund.de/api/errors/validationerror",
  "title": "ValidationError",
  "status": 400,
  "detail": "Invalid input.",
  "errors": {
    "status": [
      "The PAID payment status is derived exclusively from recorded payments."
    ]
  },
  "validation_errors": [
    {
      "field": "status",
      "message": "The PAID payment status is derived exclusively from recorded payments."
    }
  ]
}

To correct or cancel an issued invoice, POST /api/v1/invoices/{invoice_id}/correct/ with {"type_code": "381"} (credit note / cancellation invoice) or {"type_code": "384"} (corrected invoice) creates a new draft that refers to the invoice as preceding invoice. The invoice itself stays unchanged; to cancel it, set it to cancelled as above.

4. Record a payment

POST /api/v1/managed-invoices/{id}/add-payment/ records a payment: amount is required, payment_date (default today), method, reference and note are optional. If the payments cover the amount due, the status becomes paid; a part payment gives partially_paid.

curl (Shell)
curl -sS -X POST "https://www.e-rechnungsfreund.de/api/v1/managed-invoices/$MANAGED_ID/add-payment/" \
  -H "Authorization: Api-Key $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"amount": "904.40", "payment_date": "2026-10-15", "method": "SEPA credit transfer", "reference": "RE-2026-001"}' \
  | jq '{status, paid_amount, open_amount, payment_id}'
Python (requests)
payment = requests.post(
    f"{BASE_URL}/api/v1/managed-invoices/{managed_id}/add-payment/",
    json={
        "amount": "904.40",
        "payment_date": "2026-10-15",
        "method": "SEPA credit transfer",
        "reference": "RE-2026-001",
    },
    headers=HEADERS,
    timeout=30,
)
payment.raise_for_status()
data = payment.json()
print(data["status"], data["open_amount"])  # paid 0.00
Example response: POST /api/v1/managed-invoices/{id}/add-payment/ → 200 OK

Excerpt: the response contains all fields of the managed invoice and payment_id, the ID of the new payment.

JSON
{
  "id": 1234,
  "status": "paid",
  "paid_amount": "904.40",
  "open_amount": "0.00",
  "paid_at": "2026-10-15T08:00:00.000000Z",
  "payment_id": 1,
  "payments": [
    {
      "id": 1,
      "amount": "904.40",
      "payment_date": "2026-10-15",
      "method": "SEPA credit transfer",
      "reference": "RE-2026-001",
      "note": "",
      "created_at": "2026-10-15T08:00:00.000000Z"
    }
  ]
}

A payment above the open amount gives 400. A wrong entry can be corrected with POST /api/v1/managed-invoices/{id}/payments/{payment_id}/update/ or removed with POST /api/v1/managed-invoices/{id}/payments/{payment_id}/delete/; the status is then recalculated.

5. Query invoices

GET /api/v1/managed-invoices/ lists your managed invoices, newest issue date first. Filters, all optional: direction, status, due_state (open, overdue, paid), periods for the issue date, the due date and the date of full payment (paid_date_from, paid_date_to) and q for the invoice number and names. The example lists the outgoing invoices paid in October:

curl (Shell)
curl -sS -i "https://www.e-rechnungsfreund.de/api/v1/managed-invoices/?direction=outgoing&due_state=paid&paid_date_from=2026-10-01&paid_date_to=2026-10-31&limit=50" \
  -H "Authorization: Api-Key $API_KEY"

# open amounts of all outgoing invoices
curl -sS "https://www.e-rechnungsfreund.de/api/v1/managed-invoices/?direction=outgoing&due_state=open" \
  -H "Authorization: Api-Key $API_KEY" \
  | jq '.[] | {invoice_number, buyer_name, open_amount, payment_due_date}'
Python (requests)
params = {
    "direction": "outgoing",
    "due_state": "paid",
    "paid_date_from": "2026-10-01",
    "paid_date_to": "2026-10-31",
    "limit": "50",
    "offset": 0,
}
while True:
    page = requests.get(
        f"{BASE_URL}/api/v1/managed-invoices/",
        params=params,
        headers=HEADERS,
        timeout=30,
    )
    page.raise_for_status()
    for row in page.json():
        print(row["invoice_number"], row["buyer_name"], row["paid_amount"], row["paid_at"])
    params["offset"] += int(params["limit"])
    if params["offset"] >= int(page.headers["X-Total-Count"]):
        break
Example response: GET /api/v1/managed-invoices/?direction=outgoing&due_state=paid&paid_date_from=2026-10-01&paid_date_to=2026-10-31&limit=50 → 200 OK
JSON
HTTP/1.1 200 OK
Content-Type: application/json
X-Total-Count: 1

[
  {
    "id": 1234,
    "invoice_id": "3ff6fce7-0c0f-4726-8288-92947decc8aa",
    "invoice_number": "RE-2026-001",
    "buyer_name": "Käufer AG",
    "seller_name": "Muster GmbH",
    "direction": "outgoing",
    "issue_date": "2026-10-01",
    "payment_due_date": null,
    "due_payable_amount": "904.4000",
    "paid_amount": "904.40",
    "open_amount": "0.00",
    "status": "paid",
    "export_status": "ready",
    "source_file": null,
    "is_overdue": false,
    "updated_at": "2026-10-15T08:00:00.000000Z",
    "paid_at": "2026-10-15T08:00:00.000000Z"
  }
]
  • X-Total-Count is the number of matching invoices; page with limit (1–500) and offset.
  • The date of full payment is paid_at, the time at which the last payment was recorded, not the payment_date of the payment.

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

Next steps