Invoice Ledger

n8n invoice automation: PDF invoice emails into one CSV ledger

The mechanics of the pipeline, node by node, including the part everyone skips: what happens when the same invoice arrives twice.

Guide · node parameters checked against n8n documentation on 22 October 2026 · works with JavaScript switched off

The shape of the problem

An invoice email is a small, well-defined document: a supplier, an invoice number, a date, a currency, a net amount, a tax amount and a total. The difficulty is not reading one of them — it is that the same invoice arrives more than once: forwarded, re-sent, copied to a second mailbox, or delivered again after a mail rule misfires. A pipeline that appends whatever it sees double-counts spend, and a ledger you cannot trust is worse than a spreadsheet you keep by hand.

So the workflow has four stages, and the last one is the point: trigger on a message with a PDF attached, get the text layer out, parse the fields and check the arithmetic, then write the row only if it is not already there.

Step 1 — trigger on mail, not on the inbox

Two triggers work, and the choice is about which mailbox you have.

Gmail Trigger

One event, Message Received, fired at the poll time you choose. The parameters that matter, as documented:1

IMAP Email trigger

Works with any mailbox that speaks IMAP, which is what most self-hosters actually have, and it is what the free preview workflow in this project uses. Three settings on that node decide what happens to your mail, and all three are documented:5

A dedicated mailbox, or a folder rule, is the cheapest way to keep this out of your working inbox. Attachments, collisions and read flags have a page of their own.

Step 2 — get the text layer out of the PDF

The Extract From File node takes a binary file and turns it into JSON. The operation you want is Extract From PDF.4

This reads the text layer — the characters a PDF stores for searching and copying. It does not do OCR. A scan, a phone photo, or a PDF exported from a print-to-PDF printer at low quality has no text layer, and the extraction returns little or nothing. That is not a bug to work around with a bigger model; it is a different problem with a different cost.

If your PDFs come from suppliers' accounting systems — which is most of them — the text layer is there and this step is instant.

Step 3 — parse, and make the arithmetic prove itself

A Code node with plain regular expressions is enough, and anyone who reads JavaScript can inspect it. The patterns that cover most supplier layouts look for:

Then the check that catches most bad parses without any AI:

const ok = Math.abs((net + vat) - total) <= 0.02;

If net plus tax does not equal the total within a cent or two, the parser has read at least one of the three numbers wrong. The free starter workflow in this project does exactly this check and reports the failure in plain words rather than writing a wrong row.

Write down what you could not read. Every row should carry a status and a reason string. The paid pack uses four: ok, needs_review (either the arithmetic failed or the fields could not be read at all — the reason column says which), duplicate and possible_duplicate. A ledger where "missing" and "wrong" look the same is worse than one that admits both.

Step 4 — three duplicate checks, in this order

The order matters, because each check is more permissive than the one before it.

  1. Exact. Same supplier and same invoice number as a row already in the ledger → duplicate, not written. This catches the forward, the re-send and the second mailbox.
  2. Probable. Same supplier, same total, within a short window (21 days is a reasonable default), but a different invoice number → possible_duplicate, written but excluded from totals until a human confirms. This catches the supplier who re-issues under a new number without crediting the old one.
  3. Arithmetic. A total that fails net + vat → needs_review, regardless of whether it is a duplicate, because a misparse and a duplicate are different problems and you want to see both.

Idempotency is the test: run the workflow twice over the same mailbox and the CSV must be byte-identical after the second run. If a timestamp or a run ID lands in the file, that test will never pass and the file stops being diffable.

One more case worth deciding in advance: a corrected re-issue. Same invoice number, corrected amount. Check 1 classes it as a duplicate and the wrong amount stays. Either accept editing the row by hand, or key the ledger on supplier + number + version and accept a slightly messier file. Decide deliberately; do not discover it at quarter end.

Start with one invoice, not with the mailbox

Before any of the above touches a real inbox, read a single PDF and look at what came back. The free starter in this project does exactly that: a form upload, the extraction, the parse, the arithmetic check, and a plain answer — no credential, no ledger, nothing written. It is the file free-01-read-one-invoice.json on the free workflows page (the same starter is on n8n.io), next to free-03-check-invoice-csv-duplicates.json, which runs two of the three checks above over a CSV you already have: the exact one (same supplier, same number) and the probable one (same supplier, same date and total). The arithmetic check lives in free-01, and the "same supplier and amount under a different number" rule is only in the paid pack.

Then the mailbox preview, free-02-inbox-preview.json, which reads and reports but writes nothing.

If the free starter reads your suppliers' invoices correctly, the pack will too — it is the same parser. If it does not, USD 49 will not fix that, and the 14-day fix-or-refund in the terms exists precisely for the case where it does not: we first try to fix it, and refund if we cannot.

Where to run it

The three free starters write nothing, so they run on n8n Cloud as they are — start n8n Cloud. The ledger itself writes CSV files into the instance's own folder, and n8n documents no way to reach or keep that folder on Cloud: the documented Cloud backup route exports workflows, not the instance directory.6 That is why the paid pack is documented as self-hosted. On Cloud the file nodes would have to become a storage node — and you maintain that.

Honest limits

Troubleshooting

The eleven-workflow version

The pack adds the parts a business needs after the first working pipeline: the review queue for rows that need a human, approval requests over a threshold with a callback that records the decision, bank reconciliation against the ledger, a duplicate-payment alert, a VAT quarter summary, currency normalisation, an accounting export, a monthly close pack, and a nightly dated copy of the ledger.

Invoice Ledger — 11 workflows, USD 49

One business, one purchase, 14-day fix-or-refund if it does not import or cannot read your invoices. What is in it, in detail.

Sources

  1. n8n docs — Gmail Trigger (Message Received event; Max Emails per Poll default 10, maximum 50; Search, Label, Read Status, Simplify). Read 2026-10-22.
  2. Gmail Help — Refine searches in Gmail (has: and filename: operators). Read 2026-10-22.
  3. n8n docs — Gmail message operations (Simplify returns metadata only: IDs, labels and headers). Read 2026-10-22.
  4. n8n docs — Extract From File (operation “Extract From PDF” converts a binary file to JSON). Read 2026-10-22.
  5. n8n docs — IMAP Email node (Mark as Read: None or Mark as Read; Download Attachments toggle and its processing cost; Format Resolved versus Simple). Read 2026-10-22.
  6. n8n docs — Download workflows (n8n Cloud) (the documented Cloud backup is a workflow download from the admin dashboard, not the instance folder). Read 2026-10-22.

Version note: the n8n documentation was read on 2026-10-22, when the published npm latest for n8n was 2.44.5. The workflows in this project were built and tested on 2.44.4.