n8n Invoice PDF Generation, No Duplicates
说明与用途
一份 n8n 自动化配方,防止重复发票,处理 webhook 重试,生成 PDF,发送邮件,并在 Google Sheet 中记录结果。
问题
Webhook retries or PDF service hiccups cause duplicate invoices or silent failures.
结果
The recipe prevents duplicate invoices, handles retries gracefully, and provides transparent logging of successes and failures.
工作流
- 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.
证据
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.
Add a Webhook node (POST, path /invoice) as the trigger, then a Code node right after it.
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.
- 记录日期: 2026-10-10T21:41:01.227Z