n8n Invoice PDF Generation, No Duplicates
Описание и применение
Рецепт автоматизации n8n, предотвращающий дублирование счетов‑платежей, обрабатывающий повторные вебхуки, генерирующий 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