Workflow 02 / Finance
Invoice OCR to Google Sheets
Supplier PDFs read, checked and filed. Doubtful ones go to a human review tab.
- Trigger
- New PDF in a Drive folder
- Size
- 11 nodes, 4 credentials
- Typical build
- 8 working days
- Tools
- n8n, Google Drive, OpenAI API, Google Sheets, Slack
Example scenario: Logistics company, about 900 supplier invoices a month, one finance team
The problem
Finance typed 900 supplier PDFs a month into the accounts-payable ledger. Each invoice took four to six minutes, typos caused duplicate payments twice a quarter and month-end close slipped by three days.
What the workflow does
The solution
n8n watches a shared Drive folder. Each new PDF is downloaded, its text is extracted and an LLM returns ten structured fields. A validation step checks the mandatory fields, that every amount is a real number, that net plus VAT equals the total and that confidence is at least 0.85. A lookup then checks whether the same supplier and invoice number are already in the ledger. Clean, new invoices go straight to the ledger; anything doubtful or duplicated lands in a review tab with the reason and pings the AP channel.
The flow
Drawn from the real JSON
Node names, order and branches are read from the exported file at build time, so this diagram can never drift from what n8n will show you. Dashed lines are connections; amber ones leave an IF, a Switch or an error output.
Download n8n JSONScroll sideways to see all branches
Node by node
| # | Node | Type | What it does |
|---|---|---|---|
| 01 | Drive: New Invoice PDF | Trigger | Watches the inbox folder for new PDFs, every 5 minutes |
| 02 | Drive: Download | App action | Downloads the file as binary |
| 03 | Extract PDF Text | Transform | Extracts the text layer of the PDF |
| 04 | LLM: Extract Fields | AI step | Chat completion (gpt-4o-mini), JSON-only output |
| 05 | Parse Invoice | Transform | Parses the LLM answer and checks mandatory fields, finite amounts and the VAT balance. |
| 06 | Sheets: Find Duplicate | App action | Looks up an existing row in the "Invoices" tab |
| 07 | IF: Valid & New | Branch | True if valid && !json['Invoice #'] is true |
| 08 | Sheets: AP Ledger | App action | Appends a row to the "Invoices" tab |
| 09 | Sheets: Review Queue | App action | Appends a row to the "Needs review" tab |
| 10 | Drive: Move to Processed | App action | Moves the PDF to the Processed folder |
| 11 | Slack: #ap-review | App action | Posts a message to #ap-review |
How a run goes
Google Drive trigger polls the AP inbox folder every 5 minutes for new PDFs.
The file is downloaded as binary and the PDF text is extracted in n8n.
The LLM returns supplier, invoice number, dates, currency, net, VAT, total, PO and a confidence value.
A Code node parses the JSON and lists every issue: missing fields, non-numeric amounts, totals that do not balance, low confidence.
Google Sheets looks up the supplier and invoice number in the ledger to catch duplicates.
IF valid and new: append to the AP ledger and move the PDF to "Processed".
Otherwise: append to the "Needs review" tab with the reason and post the PDF link to Slack.
Tools and credentials
Credentials are referenced by name inside the JSON. Create each one in n8n under Credentials, using these names, and the nodes connect automatically.
| Credential name | What you need |
|---|---|
| Google Drive – Finance | Google OAuth client with the Drive API enabled |
| OpenAI – Flowforge | API key from platform.openai.com |
| Google Sheets – Ops | Google OAuth client with the Sheets API enabled |
| Slack – Flowforge Bot | Bot token with the chat:write scope |
Setup in about 30 minutes
Import the file. In n8n open Workflows, then Import from file, and pick
invoice-ocr.json. The workflow arrives inactive.Create the 4 credentials listed above with exactly those names.
Replace the placeholders with your own IDs:
REPLACE_WITH_INBOX_FOLDER_IDin “Drive: New Invoice PDF”REPLACE_WITH_LEDGER_SHEET_IDin “Sheets: Find Duplicate”REPLACE_WITH_LEDGER_SHEET_IDin “Sheets: AP Ledger”REPLACE_WITH_LEDGER_SHEET_IDin “Sheets: Review Queue”REPLACE_WITH_PROCESSED_FOLDER_IDin “Drive: Move to Processed”
Adapt it to your business.
- Create two Drive folders, Inbox and Processed, and paste their IDs into the trigger and the move node.
- Create the ledger sheet with an "Invoices" tab and a "Needs review" tab; column headers must match the field names in the Sheets nodes. The duplicate lookup reads the "Supplier" and "Invoice #" columns of the Invoices tab.
- Scanned PDFs have no text layer: add an OCR step (for example Google Vision) before "Extract PDF Text" if your suppliers send images.
- Tune the 0.85 confidence limit in the "Parse Invoice" Code node after the first 50 invoices.
Connect error reporting. Import
error-reporter.jsononce, then open this workflow’s Settings and choose it as the Error workflow. Failed runs are posted to Slack and logged, with a link to retry.Test, then activate. Run the first node with sample data, check each output in the execution view, then switch the workflow to active. Keep the test run for your records.
Example figures for the scenario above, not guarantees
What this kind of build changes
Use it, or have it built for you
The JSON is free to import and adapt. If you would rather have it wired to your own stack and tested on your data, a single flow like this is a fixed-price project.