{
  "name": "Valifakt: validate an XRechnung and convert an invoice row to XRechnung",
  "nodes": [
    {
      "parameters": {},
      "id": "9a9d2558-53ae-5b2c-94bb-4e7896a78d24",
      "name": "When clicking 'Execute workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        200
      ]
    },
    {
      "parameters": {
        "url": "https://valifakt.com/assets/samples/xrechnung-ubl-beispiel.xml",
        "options": {
          "response": {
            "response": {
              "responseFormat": "file"
            }
          }
        }
      },
      "id": "44b3f8ec-a578-5c4a-afd2-8d21dbc865c5",
      "name": "Download sample XRechnung",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        260,
        80
      ]
    },
    {
      "parameters": {
        "operation": "validate",
        "binaryPropertyName": "data",
        "validateOptions": {}
      },
      "id": "e1213323-34bc-5e17-b2a0-d5289db50801",
      "name": "Validate XRechnung",
      "type": "n8n-nodes-valifakt.valifakt",
      "typeVersion": 1,
      "position": [
        520,
        80
      ],
      "credentials": {
        "valifaktApi": {
          "id": "valifakt-credential",
          "name": "Valifakt account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// One invoice per item, e.g. a row from Google Sheets, Excel 365, Airtable or your ERP.\n// Replace this node with your data source; keep the field names (or adapt the next node).\nreturn [{ json: {\n  invoice_number: 'RE-2026-0101',\n  invoice_date: '01.12.2026',\n  delivery_date: '28.11.2026',\n  due_date: '31.12.2026',\n  order_reference: 'PO-7781',\n  seller_name: 'Muster Software GmbH',\n  seller_street: 'Hauptstraße 12',\n  seller_city: '10115 Berlin, Deutschland',\n  seller_vat_id: 'DE123456788',\n  seller_email: 'rechnung@muster-software.example',\n  seller_phone: '+49 30 1234567',\n  seller_contact: 'Buchhaltung',\n  seller_iban: 'DE89 3704 0044 0532 0130 00',\n  seller_bic: 'COBADEFFXXX',\n  buyer_name: 'Beispiel Handel GmbH',\n  buyer_street: 'Lindenweg 5',\n  buyer_city: '80331 München, Deutschland',\n  buyer_vat_id: 'DE987654328',\n  buyer_email: 'einkauf@beispiel-handel.example',\n  payment_terms: '30 Tage netto',\n  items: [\n    { description: 'Softwarelizenz Jahresabo', quantity: 1, unit: 'Stk', unit_price: 1200.00, vat: 19 },\n    { description: 'Einrichtung und Schulung', quantity: 6, unit: 'Std', unit_price: 95.00, vat: 19 },\n  ],\n} }];"
      },
      "id": "8e014e32-f8fa-588c-8e3a-283e4af38f2d",
      "name": "Invoice row",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        260,
        320
      ]
    },
    {
      "parameters": {
        "jsCode": "// Lays one invoice row out as a simple invoice sheet (label | value rows + an item table),\n// which the Valifakt converter reads like an Excel invoice. One output item = one spreadsheet row.\nconst eur = (n) => n.toFixed(2).replace('.', ',').replace(/\\B(?=(\\d{3})+(?!\\d))/g, '.');\nconst r = $input.first().json;\nconst rows = [];\nconst add = (...cells) => {\n  const o = {};\n  'ABCDEFG'.split('').forEach((k, i) => (o[k] = cells[i] === undefined ? '' : String(cells[i])));\n  rows.push({ json: o });\n};\nadd('Verkäufer:'); add(r.seller_name); add(r.seller_street); add(r.seller_city);\nadd('USt-IdNr.: ' + r.seller_vat_id); add('E-Mail: ' + r.seller_email); add('Tel.: ' + r.seller_phone);\nadd('Ansprechpartner: ' + r.seller_contact);\nadd('Rechnungsempfänger:'); add(r.buyer_name); add(r.buyer_street); add(r.buyer_city);\nadd('USt-IdNr.: ' + r.buyer_vat_id); add('E-Mail: ' + r.buyer_email);\nadd('Rechnung');\nadd('Rechnungsnummer', r.invoice_number); add('Rechnungsdatum', r.invoice_date);\nadd('Lieferdatum', r.delivery_date); add('Fällig am', r.due_date);\nadd('Bestellnummer', r.order_reference);\nadd('Pos', 'Bezeichnung', 'Menge', 'Einheit', 'Einzelpreis', 'USt', 'Netto');\nconst byRate = {};\nlet net = 0;\nr.items.forEach((it, i) => {\n  const line = Math.round(it.quantity * it.unit_price * 100) / 100;\n  net += line; byRate[it.vat] = (byRate[it.vat] || 0) + line;\n  add(i + 1, it.description, it.quantity, it.unit, eur(it.unit_price), it.vat + ' %', eur(line));\n});\nadd('Summe netto', eur(net) + ' EUR');\nlet tax = 0;\nfor (const [rate, base] of Object.entries(byRate)) {\n  const t = Math.round(base * Number(rate)) / 100; tax += t;\n  add(`USt ${rate} % auf ${eur(base)}`, eur(t) + ' EUR');\n}\nadd('Gesamtbetrag', eur(net + tax) + ' EUR');\nadd('Zahlungsbedingungen: ' + r.payment_terms);\nadd(`IBAN: ${r.seller_iban}  BIC: ${r.seller_bic}`);\nreturn rows;"
      },
      "id": "4141905a-716d-5d8a-be12-f3aab2174683",
      "name": "Lay out invoice sheet",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        520,
        320
      ]
    },
    {
      "parameters": {
        "operation": "xlsx",
        "options": {
          "fileName": "={{ $('Invoice row').first().json.invoice_number }}.xlsx",
          "headerRow": false,
          "sheetName": "Rechnung"
        }
      },
      "id": "597ebf5a-c86f-5e7c-a460-699d27f1384f",
      "name": "Excel file",
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        780,
        320
      ]
    },
    {
      "parameters": {
        "operation": "convert",
        "binaryPropertyName": "data",
        "format": "xrechnung-ubl",
        "options": {}
      },
      "id": "2f2a59a3-f7c8-533b-8c58-dfd6ea5931b6",
      "name": "Convert to XRechnung",
      "type": "n8n-nodes-valifakt.valifakt",
      "typeVersion": 1,
      "position": [
        1040,
        320
      ],
      "credentials": {
        "valifaktApi": {
          "id": "valifakt-credential",
          "name": "Valifakt account"
        }
      }
    },
    {
      "parameters": {
        "operation": "getQuota"
      },
      "id": "4cb7544f-3aa7-51f6-b30d-e0bd948abc66",
      "name": "Get quota",
      "type": "n8n-nodes-valifakt.valifakt",
      "typeVersion": 1,
      "position": [
        1300,
        320
      ],
      "credentials": {
        "valifaktApi": {
          "id": "valifakt-credential",
          "name": "Valifakt account"
        }
      }
    },
    {
      "parameters": {
        "content": "## Valifakt: validate + convert e-invoices\n\n**Top:** downloads a sample XRechnung and checks it with the official KoSIT validator (free, does not use conversion quota).\n\n**Bottom:** turns one invoice row (replace *Invoice row* with Google Sheets, Excel 365, Airtable, your ERP …) into an Excel invoice and converts it into a valid **XRechnung 3.0 UBL**. The XML is in the binary field `xml` of *Convert to XRechnung*; send it by e-mail, upload it to a portal or store it.\n\nCredential: Valifakt API key (`vf_…`) from https://valifakt.com/en/pricing.html\n\nNode: `n8n-nodes-valifakt` · Docs: https://valifakt.com/en/n8n-e-invoice.html",
        "height": 420,
        "width": 420
      },
      "id": "51f2c1c8-4782-5617-9cd7-dfdf435de455",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -480,
        60
      ]
    }
  ],
  "connections": {
    "When clicking 'Execute workflow'": {
      "main": [
        [
          {
            "node": "Download sample XRechnung",
            "type": "main",
            "index": 0
          },
          {
            "node": "Invoice row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download sample XRechnung": {
      "main": [
        [
          {
            "node": "Validate XRechnung",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Invoice row": {
      "main": [
        [
          {
            "node": "Lay out invoice sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lay out invoice sheet": {
      "main": [
        [
          {
            "node": "Excel file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Excel file": {
      "main": [
        [
          {
            "node": "Convert to XRechnung",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to XRechnung": {
      "main": [
        [
          {
            "node": "Get quota",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}
