Extract invoice data from Gmail PDFs to Google Drive, Sheets, and OpenAI

Go to Workflow
0 views
Built by Incrementors Incrementors
Created on August 24, 2026

Description

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
Triggers hourly from Gmail (or can be run manually to backfill a date range) and downloads email attachments.
Filters out emails from unwanted senders and extracts only PDF attachments from each message.
Finds the current month’s folder in Google Drive, then uploads each PDF and builds shareable file and folder links.
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.
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.
Waits briefly and continues processing the next PDF attachment.

Setup
Connect Gmail, Google Drive, and Google Sheets credentials, and add an OpenAI API key for both OpenAI chat model connections.
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).
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).
Edit the unwanted sender filter (or disable it) to match the email addresses you want to ignore.

Nodes Used (8)

AI Agent
@n8n/n8n-nodes-langchain.agent
Auto-fixing Output Parser
@n8n/n8n-nodes-langchain.outputParserAutofixing
Code
n8n-nodes-base.code
Gmail
n8n-nodes-base.gmail
Google Drive
n8n-nodes-base.googleDrive
Google Sheets
n8n-nodes-base.googleSheets
OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi
Structured Output Parser
@n8n/n8n-nodes-langchain.outputParserStructured