Back to Templates

Generate ZUGFeRD/Factur-X e-invoices from webhook orders with PolyDoc and email

Created by

Created by: polydoc.tech || polydoc
polydoc.tech

Last update

Last update 10 hours ago

Categories

Share


Quick Overview

This workflow receives an order via webhook, builds an EN 16931 invoice payload and HTML, generates a ZUGFeRD/Factur-X (PDF/A-3 + embedded XML) e-invoice using PolyDoc, emails the PDF to the buyer, and returns the PDF in the webhook response.

How it works

  1. Receives an HTTP POST request with an order object via an n8n webhook endpoint.
  2. Validates that the order contains at least one line item and includes either a due date or payment terms.
  3. Calculates line totals, VAT, and invoice totals, and renders a printable HTML invoice along with a structured invoice payload.
  4. Uses PolyDoc to generate a verified ZUGFeRD/Factur-X EN 16931 e-invoice PDF/A-3 from the HTML and invoice data.
  5. Sends the generated PDF to the buyer via email using SMTP.
  6. Returns the generated PDF as the webhook response, or returns a 422 JSON error if the order is invalid.

Setup

  1. Create and add a PolyDoc API credential for the PolyDoc node.
  2. Configure an SMTP credential for the Email Send node (or remove the email step if you only want to return the PDF).
  3. Copy the webhook URL and configure your source system to POST JSON to /einvoice with the required order fields (seller, buyer, and lines, plus dueDate or paymentTerms).