REST API

Rechnungen automatisch
per API generieren

Sende Rechnungsdaten per HTTP POST – erhalte ein druckfertiges PDF zurück.
Perfekt für ERP-Systeme, Webshops und eigene Software.

✓ Im Pro-Abo enthalten ✓ QR-Rechnung inklusive ✓ Kein OAuth
🔑

API Key Auth

Einfache Authentifizierung per X-API-Key Header – kein OAuth, kein Token-Refresh.

📄

PDF in einer Anfrage

Ein POST mit JSON-Body genügt. Antwort ist direkt das PDF-Binary – oder Base64 auf Wunsch.

🇨🇭

QR-Rechnung inklusive

Mit QR-IBAN im Request wird automatisch ein Schweizer Zahlungsabschnitt generiert.

🏢

Firmendaten aus Konto

Adresse, Logo und IBAN kommen aus deinem Autofactura-Konto – kein doppeltes Pflegen.

ENDPOINT POST https://app.autofactura.ch/api/extern/invoice/pdf

Request

HEADERS

X-API-Key: <dein-api-key>
Content-Type: application/json

BODY (JSON) – VOLLSTÄNDIGES BEISPIEL

{
  // Rechnung
  "invoice_number": "2026-042",
  "invoice_date":   "2026-07-15",
  "due_date":       "2026-08-14",
  "project":        "Website Relaunch",   // optional

  // Kunde
  "customer_name":           "Muster GmbH",
  "customer_contact_person": "Max Muster",  // optional
  "customer_street":         "Bahnhofstrasse",
  "customer_building_nr":    "12",
  "customer_postcode":       "8001",
  "customer_city":           "Zürich",

  // Positionen
  "items": [
    {
      "name":        "Webentwicklung – Modul A",  // oder "description"
      "subtitle":    "inkl. Testing",              // optional, kleine Zeile
      "quantity":    8,
      "price":       150.00,
      "total":       1200.00   // optional, sonst quantity × price
    },
    { "name": "Support-Pauschale Mai", "quantity": 1, "price": 250.00 }
  ],

  // Beträge (alle optional – werden aus items berechnet wenn 0)
  "subtotal":   1450.00,
  "discount":      0.00,
  "vat_rate":    "8.1",
  "vat_amount":  117.45,
  "total":      1567.45,

  "notes": "Zahlbar innert 30 Tagen. Danke!",  // optional

  // QR-Rechnung – optional, sonst aus Konto
  "qr_iban":      "CH56 0483 5012 3456 7800 9",
  "qr_reference": "210000000003139471430009017",

  // QR-Kreditor-Adresse – optional, sonst aus Konto
  "qr_creditor_name":        "Muster GmbH",
  "qr_creditor_street":      "Bahnhofstrasse",
  "qr_creditor_building_nr": "12",
  "qr_creditor_postcode":    "8001",
  "qr_creditor_city":        "Zürich",

  // Firmendaten überschreiben – optional, sonst aus Konto
  "company_name":        "Muster GmbH",
  "company_street":      "Bahnhofstrasse",
  "company_building_nr": "12",
  "company_postcode":    "8001",
  "company_city":        "Zürich",
  "company_logo":        "data:image/png;base64,iVBORw0KGgo..."
}

OPTIONALER QUERY-PARAMETER

?format=base64

Gibt JSON mit {"success":true,"pdf":"<base64>"} zurück statt Binary-PDF.

FELDER: RECHNUNG

FeldTypPflichtBeschreibung
invoice_numberstringjaRechnungsnummer
invoice_datedatejaRechnungsdatum (YYYY-MM-DD)
due_datedatejaFälligkeitsdatum (YYYY-MM-DD)
projectstringProjektname, erscheint unter Rechnungsnummer
notesstringBemerkungen / Zahlungshinweis (Fusszeile)

FELDER: KUNDE

FeldTypPflichtBeschreibung
customer_namestringjaFirmen- oder Kundenname
customer_contact_personstringKontaktperson, erscheint unter Firmenname
customer_streetstringja*Strasse (*Pflicht für QR-Rechnung)
customer_building_nrstringja*Hausnummer
customer_postcodestringja*PLZ
customer_citystringja*Ort

FELDER: POSITIONEN

FeldTypPflichtBeschreibung
itemsarrayjaArray mit Positionen (siehe unten)
items[].namestringjaBezeichnung (alternativ: description)
items[].subtitlestringZweite Zeile, kleinere Schrift
items[].quantityfloatMenge (Standard: 1)
items[].pricefloatEinzelpreis in CHF
items[].totalfloatZeilentotal (sonst quantity × price)
items[].discountfloatRabatt auf Position in CHF

FELDER: BETRÄGE

FeldTypPflichtBeschreibung
subtotalfloatZwischensumme (wird aus items berechnet wenn 0)
discountfloatGesamtrabatt in CHF
discount_labelstringBezeichnung des Rabatts (Standard: "Rabatt")
vat_ratestringMwSt-Satz z.B. "8.1" oder "manual"
vat_amountfloatMwSt-Betrag in CHF
totalfloatGesamtbetrag (wird berechnet wenn 0)

FELDER: QR-RECHNUNG (optional – sonst aus Konto)

FeldTypBeschreibung
qr_ibanstringQR-IBAN (CH…). Kein QR-Abschnitt wenn leer.
qr_referencestring27-stellige QR-Referenz (Pflicht bei QR-IBAN)
qr_creditor_namestringName des Zahlungsempfängers
qr_creditor_streetstringStrasse des Zahlungsempfängers
qr_creditor_building_nrstringHausnummer
qr_creditor_postcodestringPLZ
qr_creditor_citystringOrt

FELDER: FIRMENDATEN ÜBERSCHREIBEN (optional – sonst aus Konto)

FeldTypBeschreibung
company_namestringFirmenname
company_streetstringStrasse
company_building_nrstringHausnummer
company_postcodestringPLZ
company_citystringOrt
company_logostringLogo als Data-URI: data:image/png;base64,…

Antwort

ERFOLG – PDF BINARY

HTTP/1.1 200 OK
Content-Type: application/pdf
Content-Disposition: attachment; filename="rechnung_2026-042.pdf"

[binary PDF data]

ERFOLG – BASE64 (?format=base64)

{
  "success":  true,
  "pdf":      "JVBERi0xLj...",
  "filename": "rechnung_2026-042.pdf"
}

FEHLER

// 401 Unauthorized
{ "success": false, "error": "Ungültiger API Key" }

// 400 Bad Request
{ "success": false, "error": "Feld \"items\" ist erforderlich" }

Code-Beispiele

CURL

curl -X POST https://app.autofactura.ch/api/extern/invoice/pdf \
  -H "X-API-Key: DEIN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "invoice_number": "2026-042",
    "customer_name": "Muster AG",
    "customer_city": "Zürich",
    "customer_postcode": "8001",
    "items": [
      { "description": "Beratung", "quantity": 2, "price": 150 }
    ]
  }' \
  --output rechnung.pdf

JAVASCRIPT / FETCH

const res = await fetch(
  'https://app.autofactura.ch/api/extern/invoice/pdf?format=base64',
  {
    method: 'POST',
    headers: {
      'X-API-Key': 'DEIN_API_KEY',
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      invoice_number: '2026-042',
      customer_name: 'Muster AG',
      customer_city: 'Zürich',
      items: [{ description: 'Beratung', quantity: 2, price: 150 }],
    }),
  }
);
const { pdf } = await res.json();

PHP

$data = [
  'invoice_number' => '2026-042',
  'customer_name'  => 'Muster AG',
  'customer_city'  => 'Zürich',
  'items' => [
    ['description' => 'Beratung', 'quantity' => 2, 'price' => 150],
  ],
];
$ch = curl_init('https://app.autofactura.ch/api/extern/invoice/pdf');
curl_setopt_array($ch, [
  CURLOPT_POST           => true,
  CURLOPT_POSTFIELDS     => json_encode($data),
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER     => [
    'X-API-Key: DEIN_API_KEY',
    'Content-Type: application/json',
  ],
]);
$pdf = curl_exec($ch);
file_put_contents('rechnung.pdf', $pdf);

API Key holen

Im Autofactura Pro-Abo enthalten. Generiere deinen API Key unter Profil → Einstellungen → API Key – sofort verfügbar.

Jetzt Abo starten