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
- Polls Gmail every 5 minutes for emails with attachments.
- Reads each attachment, keeping UBL/CII invoice XML files and extracting embedded invoice XML from ZUGFeRD/Factur-X PDFs while ignoring non-invoice files.
- 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.
- Looks up existing entries in a Google Sheets “Invoices” tab to detect repeats by seller + invoice number and prevent reprocessing the same email attachment.
- Appends new invoices to Google Sheets or updates the existing row for duplicates while incrementing a duplicate counter and storing the latest validation result.
- 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.
- If the workflow or Gmail polling fails, sends a failure alert email via Gmail with the node, error message, and execution link.
Setup
- Create Gmail and Google Sheets credentials in n8n, and add an OpenAI credential only if you enable the optional OpenAI-based reply phrasing.
- 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).
- Paste your Google Sheet URL into the three Google Sheets steps that read, append, and update the invoice log.
- Review and adjust the validation and reply settings (tolerance, buyer reference requirement, whether to send replies, whether to use OpenAI, and your company name).
- 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.