See llms.txt for all machine-readable content.

Back to Templates

Register and validate XRechnung and ZUGFeRD invoices with Gmail and Sheets

Quick overview

Logs incoming e-invoices from Gmail in a Google Sheets register with duplicate tracking. Checks core EN 16931 rules, main XRechnung BR-DE rules and Leitweg-ID warnings. Reads UBL, CII and ZUGFeRD PDFs without external e-invoice APIs. A plausibility check, not a KoSIT replacement.

How it works

  1. Polls Gmail every 5 minutes for emails with attachments.
  2. Reads each attachment, keeping UBL/CII invoice XML files and extracting embedded invoice XML from ZUGFeRD/Factur-X PDFs while ignoring non-invoice files.
  3. Validates each invoice against a subset of EN 16931 core rules (mandatory fields, totals, VAT breakdown) and applies additional XRechnung BR-DE checks such as buyer reference and Leitweg-ID warnings.
  4. Looks up existing entries in a Google Sheets “Invoices” tab to detect repeats by seller + invoice number and prevent reprocessing the same email attachment.
  5. Appends new invoices to Google Sheets or updates the existing row for duplicates while incrementing a duplicate counter and storing the latest validation result.
  6. Optionally replies in the same Gmail thread when an invoice has errors or is unreadable, and optionally uses OpenAI to generate a short plain-language explanation while always including the rule list.
  7. If the workflow or Gmail polling fails, sends a failure alert email via Gmail with the node, error message, and execution link.

Setup

  1. Create Gmail and Google Sheets credentials in n8n, and add an OpenAI credential only if you enable the optional OpenAI-based reply phrasing.
  2. Create a Google Sheet with a tab named “Invoices” and add the required header row (invoice_key, duplicate_count, received_at, status, format, profile, supplier, supplier_vat_id, invoice_number, invoice_date, invoice_type, buyer, buyer_reference, currency, net_total, vat_total, gross_total, amount_due, error_count, errors, warnings, file_name, email_from, email_subject, message_id, last_duplicate_at).
  3. Paste your Google Sheet URL into the three Google Sheets steps that read, append, and update the invoice log.
  4. Review and adjust the validation and reply settings (tolerance, buyer reference requirement, whether to send replies, whether to use OpenAI, and your company name).
  5. Replace the recipient in the failure alert email, and set this workflow as its own Error Workflow so the failure alert trigger runs on errors.