See llms.txt for all machine-readable content.

Back to Templates

Check Gmail e-invoices with Dynamic Document API, Sheets, Drive and DATEV

Quick overview

This workflow monitors supplier invoice emails in Gmail, validates PDF/XML e-invoices with Dynamic Document API, stores files in Google Drive, maintains an invoice register and supplier list in Google Sheets, sends payment-due reminders by email, and exports ready invoices monthly as a DATEV Buchungsstapel CSV for your accountant.

How it works

  1. Triggers when a new Gmail message matching has:attachment label:incoming-invoices arrives and downloads its attachments.
  2. Splits each email into one item per PDF or XML attachment and validates each file with Dynamic Document API (E-Invoice → Validate) to detect e-invoices and extract invoice data.
  3. Compares validated invoices against the Google Sheets invoice register and supplier list to skip duplicates and assign statuses like ready, new_supplier, on_hold, invalid, no_einvoice, unchecked, or check_failed.
  4. Creates (or reuses) a monthly folder in Google Drive, uploads each invoice file, and appends a row to the Google Sheets invoice register with links to the Drive file and the Gmail message.
  5. Adds newly discovered suppliers to the Google Sheets supplier list, creates Gmail draft replies for invalid/missing e-invoices, and emails alert_email when new invoices need manual review.
  6. Every Monday at 07:00, reads the register and emails alert_email a list of unpaid invoices due within the configured horizon (including overdue items), highlighting invoices that are still on hold.
  7. On the 1st at 06:00, builds a DATEV Buchungsstapel CSV from ready invoices up to the end of the previous month, emails the file to accountant_email, and updates the register rows as exported or book_by_hand.

Setup

  1. Install the verified community node Dynamic Document API from the nodes panel (package @dynamic-document-api/n8n-nodes-dynamic-document-api, 0.1.2 or later, tested with 0.1.2 on n8n 2.44.4, install guide: https://dynamicdocumentapi.com/docs/n8n). Create an API key in the Dynamic Document API dashboard and add it as a Dynamic Document API credential.
  2. Add credentials for Gmail, Google Sheets, and Google Drive (OAuth) and ensure the Gmail trigger query matches your labeling/filtering (default: label:incoming-invoices).
  3. Create a Google Sheet with two tabs, Invoices and Suppliers, using the column headers expected by the workflow, then paste the tab URLs into invoices_sheet_url and suppliers_sheet_url in Inbox settings.
  4. Create a Google Drive parent folder for invoice storage and set its drive_folder_id, plus update company_name, own_vat_id, alert_email, accountant_email, timezone, and (if needed) DATEV parameters like consultant/client numbers and default accounts.
  5. Email yourself a supplier invoice with the label, check the register and the drafts, then publish the workflow.

Requirements

  • n8n (Cloud or self-hosted) with the verified Dynamic Document API community node 0.1.2 or later (E-Invoice → Validate; if that operation is missing, update the node), tested on n8n 2.44.4
  • Dynamic Document API account: checking e-invoices is part of every plan, one render per check with a live key; a test key checks 25 a day for free
  • Google account with Gmail, Google Sheets and Google Drive credentials in n8n
  • An accountant who works with DATEV, for the monthly export (the register and due list work without it)

Customization

  • Change the DATEV accounts and tax keys in Inbox settings (datev_default_creditor, datev_default_expense_account, datev_tax_keys); the defaults are SKR03, the note lists SKR04. Per supplier, the supplier list holds the creditor, expense account and a tax key for EU acquisitions and reverse charge
  • Turn off the request for an e-invoice with ask_for_einvoice, and change due_within_days for the due list
  • Edit the wording of the draft replies in Check supplier, IBAN and duplicates
  • Swap Gmail for Outlook or IMAP, or Google Sheets for another table

Additional info

Tested against the live API with real e-invoices: XRechnung CII, a ZUGFeRD PDF with two VAT rates, a UBL credit note, goods from an Austrian supplier (intra-EU acquisition), services from a Dutch supplier with a new IBAN (reverse charge), an XML with a wrong total, a plain PDF and the same invoice sent twice. Each ended in the expected status, draft or skip; a second run of the same emails added nothing. The DATEV file passed the field patterns of DATEV's format check program, and a second export found nothing to book. Replies are always drafts. The JSON contains no credentials or private IDs. Agree the DATEV accounts and tax keys with your accountant before the first import.