Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

n8n Invoice PDF Generation, No Duplicates

Description and use

An n8n automation recipe that avoids duplicate invoices, handles webhook retries, renders PDFs, emails them, and logs outcomes in Google Sheets.

Problem

Webhook retries or PDF service hiccups cause duplicate invoices or silent failures.

Outcome

The recipe prevents duplicate invoices, handles retries gracefully, and provides transparent logging of successes and failures.

Workflow

  • 1. Trigger webhook (POST /invoice).
  • 2. Code node validates payload, calculates totals in cents, and creates idempotencyKey.
  • 3. Google Sheets node reads ledger to check if idempotencyKey exists; if so, skip PDF generation.
  • 4. If new, PDF node (self‑hosted converter) renders invoice PDF.
  • 5. Send Email node attaches PDF and sends to customerEmail.
  • 6. Google Sheets node writes status, errorMessage, and updatedAt for each run.

Evidence

The happy path was never the hard part here. Making it survive a retry, a slow dependency, or a bad payload without either duplicating or silently vanishing is.

Source

Add a Webhook node (POST, path /invoice) as the trigger, then a Code node right after it.

Source

I wrote this as a plain Node script first and ran it against a normal multi‑line invoice, a repeat of the same order ID (confirming it hashes to the same key both times), a payload missing required fields, and a line item with a zero quantity and a negative price.

Source

  • Record date: 2026-10-10T21:41:01.227Z