Extract invoice data from Gmail PDF invoices into a Google Sheets CRM with OpenRouter

Go to Workflow
0 views
Built by Sufyan Uraizee Sufyan Uraizee
Created on August 29, 2026

Description

Quick overview
This workflow polls Gmail for new invoice emails, extracts text from PDF attachments, uses OpenRouter to parse key invoice fields, and appends the results to a Google Sheets “Invoice” tab, while sending non-PDFs or unreadable PDFs to a “Review” tab for manual handling.

How it works
Polls Gmail every minute for new emails and downloads any attachments.
Splits each email into one item per attachment so multiple invoices in a single email are processed separately.
Checks whether each attachment is a PDF and sends non-PDF attachments to a Google Sheets “Review” tab.
Extracts text from each PDF and routes files with no extracted text (for example, scanned/image-only PDFs) to the “Review” tab.
Sends the extracted invoice text to an OpenRouter chat model and parses the response into structured fields like vendor, invoice number, dates, and totals.
Adds metadata such as received date, source email address, and a “New” status, then appends the final record to a Google Sheets “Invoice” tab.

Setup
Connect your Gmail OAuth2 credentials and choose which mailbox/filters to monitor in the Gmail trigger.
Add an OpenRouter API credential and select a model in the OpenRouter node.
Connect your Google Sheets OAuth2 credential and select the target spreadsheet and sheet tabs in both Google Sheets append actions.
Create a Google Sheets file with an “Invoice” tab and a “Review” tab using headers that match the extracted fields (for example: vendor_name, invoice_number, invoice_date, due_date, subtotal, tax, total_amount, currency, line_items_summary, source_email, received_date, status).

Requirements
An OpenRouter account (free signup, no card required) — or swap in any other AI provider node (Open AI or Claude)

Customization
Swap the OpenRouter model for any model you prefer (Claude, GPT, Gemini, Llama, etc.), its a customizable template
Add or remove fields extracted from each invoice by editing the "Invoice Fields Parser" schema
Replace Google Sheets with Airtable, a database (Postgres/MySQL), or a CRM if you'd rather log invoices there
Adjust the Gmail filter (label, sender, subject) to narrow which emails get scanned
Add a Slack/email notification step after a new invoice is logged

Additional info
This workflow only processes emails that actually have a PDF attachment — emails with no attachment are skipped entirely before anything runs, so you're never charged for AI calls on spam or plain-text emails. It also handles multiple invoices sent in a single email (each PDF attachment is processed separately), and routes anything that fails text extraction (e.g. scanned/image-only PDFs) to a separate "Review" sheet instead of guessing at the data.

Nodes Used (5)

AI Agent
@n8n/n8n-nodes-langchain.agent
Code
n8n-nodes-base.code
Google Sheets
n8n-nodes-base.googleSheets
OpenRouter Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenRouter
Structured Output Parser
@n8n/n8n-nodes-langchain.outputParserStructured