RobotsHelp

n8n Workflow for Automatic Invoice Processing: Gmail to Sheets, No Typing

Written by

in

It’s the end of the month. Somewhere in your inbox are 20 supplier invoices, a few of them forwarded twice, one of them a phone photo of a paper receipt, and you need all of them in one sheet before your bookkeeper asks again. Here’s the short answer. An n8n workflow for automatic invoice processing watches Gmail for PDF attachments, lets an AI model (Gemini works well) read each invoice into fixed fields, writes one row per invoice to Google Sheets, labels the email so it’s never processed twice, and asks you before anything big gets marked as approved. You build it once in about an afternoon, test it on ten old invoices, and from then on your job shrinks to checking rows instead of typing them.

Below is the full build, node by node, plus what to do with scanned invoices and how to keep it cheap and safe.

Want a practical AI workflow like this every week, free?

No password needed – your reset opens instantly.

No password. Just your email, and you’re in.

What this workflow does (and what it should never do)

Look at the invoice workflows people share in n8n’s template library and the same proven shape keeps coming back: poll Gmail for emails with PDF attachments, pull the text out of the PDF, have an AI model return the invoice as structured fields, check for duplicates, append the result to a Google Sheet, and optionally route it to someone for approval (n8n template: invoice data from Gmail to Sheets, n8n template: supplier invoices with duplicate checks). We’ll use that shape and make it a bit more forgiving for a small business: it handles scans, it marks what it isn’t sure about, and it never touches money.

That last part matters. This workflow logs and flags. It does not pay, it does not email suppliers, and it does not change anything in your accounting software. You still decide what gets paid. The time you save is the typing and the hunting, which is usually the part nobody enjoys anyway.

Here is the whole thing in one view:

  1. Gmail Trigger: picks up new emails with a PDF attached.
  2. Extract From File: pulls the text out of the PDF.
  3. Information Extractor (with a Gemini chat model): turns that text into fixed fields.
  4. Edit Fields: adds a unique invoice key and a status.
  5. Google Sheets: writes or updates one row per invoice.
  6. Gmail: labels the email as done.
  7. Optional: an approval email to you for anything above your limit.

Before you build: three things to set up

1. A sheet with fixed columns

Create a Google Sheet called “Invoices” with these headers in row 1: invoice_key, supplier_name, invoice_number, invoice_date, due_date, currency, subtotal, tax_amount, total, vat_number, notes, status, email_subject. Fixed columns are what make the rest work. The AI fills the same boxes every time, so you can sort, filter and total them later.

2. A Gmail label called invoice-logged

The workflow adds this label to every email it has processed. Your trigger then skips anything with that label, which is your first protection against doing the same invoice twice.

3. Your credentials in n8n

You need a Google credential for Gmail and Sheets, and a Gemini API key. n8n’s docs walk you through the Gemini key: you create it on the API key page in Google AI Studio and paste it into a “Google Gemini(PaLM) API” credential (n8n Docs: Google Gemini credentials). On n8n Cloud you can also pick “Use Gateway credits” instead of your own key. If Gmail throws a 401 “unauthorized_client” error later, the usual fix is enabling the Gmail API in your Google Cloud project (n8n Docs: Gmail Trigger common issues).

Build the invoice workflow in n8n, node by node

Step 1: Gmail Trigger that only catches invoices

Add a Gmail Trigger with the event “Message Received”. Set the poll time to something calm, like every 15 minutes. Invoices are rarely urgent to the minute.

Under filters, put this in Search (these are normal Gmail search operators, so you can test the exact line in the Gmail search bar first, see Google: Refine searches in Gmail):

has:attachment filename:pdf -label:invoice-logged (invoice OR factuur OR rechnung OR facture OR bill)

Then change two settings that trip almost everyone:

  • Read Status. The default is “Unread emails only” (n8n Docs: Gmail Trigger). If you glance at an invoice on your phone before the next poll, it’s read, and the workflow never sees it. Set it to unread and read emails, and let the label do the skipping.
  • Simplify off, Download Attachments on. Turn Simplify off, then under Options switch on Download Attachments. The first attachment lands in a binary field called attachment_0, the second in attachment_1, and so on (that naming comes straight from the node’s code, see n8n on GitHub: Gmail Trigger node).

Max Emails per Poll defaults to 10 (maximum 50). Extra emails wait for the next poll, so a busy month-end just takes a few more rounds.

Tip: if you can, ask suppliers to send invoices to a separate address like invoices@yourcompany or set a Gmail filter that forwards them to one inbox. A narrow inbox beats a clever search line.

Step 2: Extract From File (PDF)

Add Extract From File and choose the operation “Extract From PDF”. Set Input Binary Field to attachment_0 instead of the default data (n8n Docs: Extract From File). Run it once on a test email. For an invoice made in accounting software you’ll see the invoice text in the output, messy but complete.

If it comes back empty or nearly empty, that PDF is a scan or a photo. Skip ahead to the scanned invoice section below, then come back.

Step 3: Information Extractor with a Gemini chat model

This is the AI step. Add the Information Extractor node and attach a Google Gemini Chat Model to it. In Text, use {{ $json.text }}, which is exactly the example n8n gives for input coming from Extract From PDF (n8n Docs: Information Extractor).

For Schema Type, choose “Generate From JSON Example” and paste this. n8n only looks at the field names and types, not the values:

{
  "supplier_name": "Brightline Print Ltd",
  "invoice_number": "INV-2041",
  "invoice_date": "2026-10-02",
  "due_date": "2026-11-01",
  "currency": "EUR",
  "subtotal": 400.00,
  "tax_amount": 84.00,
  "total": 484.00,
  "vat_number": "NL000000000B01",
  "notes": ""
}

One detail from the docs worth knowing: with a JSON example, n8n treats every field as mandatory. Real invoices often miss a due date or a VAT number, so tell the model what to do when a field isn’t there. Under Options, open System Prompt Template and use something like this (n8n adds its own formatting instructions on top):

You read supplier invoices for a small business.
Copy every value exactly as it is printed. Never guess or fill in a value that is not on the invoice.
Dates: write them as YYYY-MM-DD.
Amounts: plain numbers with a dot as decimal separator, no currency symbol, no thousands separator. So "1.234,50" becomes 1234.50.
Currency: the three-letter code (EUR, GBP, USD).
If a field is not on the invoice, return an empty string (or 0 for an amount) and say which field is missing in "notes".
If subtotal plus tax does not equal the total, write "totals do not add up" in "notes".
If this is not an invoice at all (a quote, a newsletter, a delivery note), write "not an invoice" in "notes".

The number rule is the one that saves you the most cleanup. European invoices write one thousand two hundred thirty-four euros and fifty cents as 1.234,50, while a sheet expects 1234.50.

Step 4: Edit Fields to add a key and a status

Add an Edit Fields (Set) node. Drag in all the extracted fields, then add three of your own:

  • invoice_key: drag in supplier_name, type a |, then drag in invoice_number. So “Brightline Print Ltd|INV-2041”. This is how you recognise the same invoice when it arrives twice.
  • status: the fixed text to check. Every row starts there. You change it to “approved” or “paid” yourself.
  • email_subject: drag in the subject from the Gmail Trigger, so you can find the original email in seconds.

Step 5: Google Sheets, Append or Update Row

Add a Google Sheets node with the operation Append or Update Row. It updates an existing row or adds a new one if no matching row is found. Pick your Invoices sheet, choose Map Each Column Manually, and set Column to Match On to invoice_key (n8n Docs: Google Sheets sheet operations). Now a forwarded copy of the same invoice lands on the same row instead of creating a second one. That’s your second layer against double entries, and the one that catches the supplier who sends the same invoice again with “reminder” in the subject.

Step 6: Gmail, add the label

Add a Gmail node, Resource Message, Operation Add Label. For Message ID, drag in the id from the Gmail Trigger, and pick your invoice-logged label (n8n Docs: Gmail message operations). Put this node last, so an email only gets the label once its row is actually in the sheet. If something fails halfway, the email stays unlabelled and gets picked up again.

Step 7 (optional): an approval email for big invoices

Add an If node after the sheet: is total greater than your limit, say 1000? On the true branch, add a Gmail node with the operation Send and Wait for Approval, sent to yourself, with the supplier, number, total and due date in the message. Set Type of Approval to “Approve and Disapprove”. The workflow pauses until you click. After the click, a second Google Sheets node (Update Row, matched on invoice_key) sets the status to “approved” or “rejected”. n8n describes this operation as the right fit for simple approvals and points to the Wait node for anything more complex.

Still no payments. “Approved” in a sheet just means you looked at it. Paying stays in your bank or accounting tool, done by a person.

What about scanned invoices and phone photos?

A scanned PDF is basically a picture of a page, so there may be no text inside for Extract From File to pull out. This is where Gemini earns its place. Google’s documentation says Gemini processes PDFs with native vision, so it understands text, tables and images on the page, not just a hidden text layer, for files up to 50 MB or 1000 pages (Google AI for Developers: Document understanding).

In n8n you use the Google Gemini node with the operation Document > Analyze Document (n8n Docs: Google Gemini node):

  1. After Extract From File, add an If node with a Number condition: {{ $json.text.trim().length }} is less than 50. That’s your “this is a scan” test.
  2. On the true branch, add Google Gemini, Analyze Document. Set Input Type to Binary File(s) and the field name to attachment_0.
  3. As the text input, write: “Transcribe all text on this invoice exactly as printed, including every amount, date and number. Keep the table rows on separate lines.”
  4. Raise the maximum length under Options. In the node’s code the default is 300 tokens, which can cut off an invoice with many line items. 1500 is a safer start.
  5. Send the result into the same Information Extractor, so both routes end up in identical columns.

Google’s own tips for better results are simple: rotate pages the right way up and avoid blurry pages. If you photograph paper receipts, do it flat, in good light, and save the result as a PDF (use your phone’s scan-to-PDF option if it has one), so the filename:pdf filter in your trigger actually catches it.

Can Gemini automate invoice processing for a small business?

Yes, with one honest correction. Gemini is the part that reads the invoice. It doesn’t watch your inbox, it doesn’t own a spreadsheet, and it doesn’t remember which invoices it already saw. That’s the job of the workflow around it, which is why n8n and Gemini work well together: n8n does the plumbing, Gemini does the reading.

For a small business, three things decide whether it’s a good fit:

  • Your volume. If you get five invoices a month, a manual routine is fine. Drag the PDFs into a chat and ask for the fields, like in our guide on extracting data from a PDF into a spreadsheet with Claude. Once invoices arrive every week from different suppliers, the workflow pays for its afternoon of setup.
  • Your data and the free tier. Google’s pricing page lists “Content used to improve our products” under the Gemini API free tier (Gemini API pricing). Invoices carry supplier names, bank details and amounts. For real business invoices, use the paid tier, and check the current rates on that page before you start, because they change.
  • Your accountant’s needs. Ask which fields they actually want before you build the sheet. Adding a column later is easy, re-reading 200 old invoices is not.

Test it on ten real invoices before you trust it

Don’t switch it on and walk away. Pick ten invoices from last month: a few from software, at least one scan, one in a foreign currency, one with a credit note or discount. Forward them to the inbox the trigger watches, run the workflow, and compare every row against the PDF, column by column.

What usually needs fixing after the first test:

  • Supplier names that vary. “Brightline Print Ltd” and “Brightline Print” break your duplicate key. Add a line to the system prompt: “Use the legal company name as printed at the top of the invoice.”
  • Totals versus amounts due. Some invoices show a total and a lower “amount due” after a deposit. Decide which one you want and say so in the prompt.
  • Non-invoices. Quotes and order confirmations slip through the search. Filter rows with “not an invoice” in notes, or add an If node that stops them before the sheet.

Then test the duplicate guard on purpose: forward the same invoice twice and check you still have one row. Once ten in a row come out right, activate the workflow. Keep checking the “to check” rows for the first month. You’re no longer typing, you’re reviewing, and that takes a few minutes instead of an evening.

Once the data is in, you can ask questions of it at month end, like spend per supplier or what’s due next week. Our guide on analyzing a spreadsheet with ChatGPT shows how to do that without formulas.

What it costs to run

n8n itself can be free: the self-hosted Community edition is free to use indefinitely (n8n Docs: Compare editions). If you’d rather not run a server, n8n Cloud has a 14-day trial with Pro features and a limit of 1000 executions, then paid plans (n8n Docs: Try free then choose a plan). Every run of the workflow counts as an execution, so testing on a few dozen invoices sits well inside that trial.

The AI part is billed per token by Google. A one-page invoice is small: Google’s docs count each PDF page as 258 tokens, and for Gemini 3 models you aren’t charged for tokens from the text already embedded in a PDF. Check the pricing page for today’s numbers rather than trusting any figure in a blog post, including this one.

Prefer Zapier or Make? The same seven steps work there too. Our Zapier free plan automation examples and the Make.com client onboarding build show how those tools think about triggers and steps. And if your CRM is already running on n8n, the n8n CRM automation guide uses the same Gmail and Sheets credentials, so you’ve done half the setup.

Four mistakes that make invoice automation fail

  1. No label, no key. Without the invoice-logged label and the invoice_key match, a re-sent invoice becomes a second row and sooner or later a second payment.
  2. Letting it run unread-only. You read the email on your phone, the trigger skips it, and the invoice quietly goes missing from the sheet.
  3. Trusting it from day one. AI reads invoices well, not perfectly. The “to check” status is there for a reason.
  4. Letting the workflow pay or reply. Keep money and supplier contact with a person. An automation that logs wrong is a small fix. One that pays wrong is a phone call to your bank.

FAQ

Do I need to know how to code to build this?

No. Every step above is a node you configure with dropdowns and drag-and-drop. The only things that look like code are two short expressions in double curly brackets, which you can copy as they are, and the JSON example, which is just a list of field names.

Can n8n read invoices that aren’t PDFs?

Extract From File also handles formats like CSV, XLSX and plain text files. Word files aren’t on its list, so ask those suppliers for a PDF. For photos, the Google Gemini node has an Analyze Image operation that works the same way as Analyze Document. Most suppliers send PDFs, so start there and add other routes only when you actually receive them.

What if two suppliers use the same invoice number?

That’s why the key combines supplier name and invoice number. “INV-1001” from two different suppliers gives two different keys, so two rows.

Build it this week

Make the sheet and the label tonight. Tomorrow, build steps 1 to 6 and run them on ten old invoices. Add the scan route and the approval email only when you need them. The first month-end you spend checking rows instead of typing them is when you’ll know it was worth it.

Want a new practical AI workflow like this every week?

No password needed – your reset opens instantly.

No password. Just your email, and you’re in.

Never built anything in n8n before? Start with our n8n tutorial for beginners, then come back and set up the invoice flow.

Still deciding between building this yourself and paying for a ready-made tool? Our guide to AI invoice processing software compares the main types of tool and shows how to test one on your own invoices before you pay.

Sources

🇳🇱 Deze pagina in het Nederlands  ·  🇩🇪 Diese Seite auf Deutsch