Extract invoice data from Gmail PDFs to Google Drive, Sheets, and OpenAI
Ready for 3.0Ready for 3.0. This template uses no nodes that n8n 3.0 removes. No removed nodes, versions or helpers found. Static check, last run 2026-10-19.
Worth a look
- Gmail Trigger below v1.4 runs as v1.4 (drafts skipped, max emails per poll) (Check inbox hourly)
Nodes used (16)
- OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - Merge
n8n-nodes-base.merge - Extract from File
n8n-nodes-base.extractFromFile - Auto-fixing Output Parser
@n8n/n8n-nodes-langchain.outputParserAutofixing - Structured Output Parser
@n8n/n8n-nodes-langchain.outputParserStructured - Code
n8n-nodes-base.code - Google Drive
n8n-nodes-base.googleDrive - Filter
n8n-nodes-base.filter - If
n8n-nodes-base.if - AI Agent
@n8n/n8n-nodes-langchain.agent - Wait
n8n-nodes-base.wait - Gmail Trigger
n8n-nodes-base.gmailTrigger - Google Sheets
n8n-nodes-base.googleSheets - Loop Over Items (Split in Batches)
n8n-nodes-base.splitInBatches - Gmail
n8n-nodes-base.gmail - Manual Trigger
n8n-nodes-base.manualTrigger
What it does
Quick overview This workflow checks Gmail for emails with PDF invoice attachments, saves each PDF to a month-based Google Drive folder, uses OpenAI to extract key invoice fields, and appends qualifying invoices to a month-named tab in Google Sheets. How it works 1. Triggers hourly from Gmail (or can be run manually to backfill a date range) and downloads email attachments. 2. Filters out emails from unwanted senders and extracts only PDF attachments from each message. 3. Finds the current month’s folder in Google Drive, then uploads each PDF and builds shareable file and folder links. 4. Extracts text from the PDF and sends it to an OpenAI-powered agent that returns structured invoice fields as strict JSON, retrying with an auto-fixing parser when needed. 5. Checks whether Sales Tax or VAT is present and appends the invoice details (including PDF URL and Drive folder link) to a Google Sheets tab named for the current month. 6. Waits briefly and continues processing the next PDF attachment. Setup 1. Connect Gmail, Google Drive, and Google Sheets credentials, and add an OpenAI API key for both OpenAI chat model connections. 2. Update the Google Sheets document ID and ensure the target spreadsheet has columns that match the mapped fields (Company Name, Invoice Number, taxes, totals, links, and capture date). 3. In Google Drive, set the parent folder ID in the Drive search step and create monthly subfolders named like YYYY-MM (for example, 2026-04). 4. Edit the unwanted sender filter (or disable it) to match the email addresses you want to ignore.