Automate Gmail Invoice Attachments to Google Drive & Sheets

This n8n workflow automates saving PDF invoice attachments from Gmail to Google Drive and extracting invoice details to Google Sheets. It saves time, eliminates manual entry errors, and organizes invoices efficiently.
gmailTrigger
googleDrive
lmOpenAi
+8
Workflow Identifier: 1960
NODES in Use: Sticky Note, Gmail Trigger, Set, If, HTTP Request, Google Drive, Gmail, Extract From File, OpenAI Model, Structured Output Parser, Google Sheets
Automate Gmail invoices with n8n and Google Drive

Press CTRL+F5 if the workflow didn't load.

Learn how to Build this Workflow with AI:

What this workflow does

This workflow watches Gmail for unread emails with PDF invoices.
It downloads these PDFs, uploads them to Google Drive in the right folder, and renames them with email subject and date.
Then it reads text from PDFs and uses OpenAI GPT-4 to find invoice details like date, description, and total price.
The details plus a file link are added to Google Sheets.
Finally, it marks emails as read to stop repeated work.
This saves lots of time, cuts errors, and keeps invoices well-organized.


Who should use this workflow

This workflow is good for people handling many invoice emails daily.
It helps if you want to stop manual copying of invoice info and file organizing.
No coding is needed but some n8n basics help.
Works best with Gmail, Google Drive, Sheets, and OpenAI GPT-4 access.


Tools and services used

  • Gmail: To check unread invoice emails and download attachments.
  • Google Drive: To store, rename, and move invoice PDFs to folders.
  • Google Sheets: To add invoice details as rows in a ledger.
  • OpenAI GPT-4: To extract invoice data from PDF text.
  • n8n: To automate the entire workflow with nodes and triggers.

Inputs, processing, and outputs

Inputs

  • Unread Gmail emails with PDF invoice attachments.
  • Google Drive folder IDs where to store files.
  • API Keys and OAuth2 credentials for Gmail, Drive, Sheets, and OpenAI.

Processing steps

  • Trigger fires every minute checking Gmail for unread emails with attachments.
  • Filters emails to allow only those with PDF invoices.
  • Downloads the PDF attachments.
  • Uploads PDF as binary to Google Drive using HTTP Request node.
  • Renames file with email subject and date using Google Drive update operation.
  • Moves file to the right client folder in Drive.
  • Downloads file from Drive for content extraction.
  • Extracts text from PDF using Extract From File node.
  • Sends text to OpenAI GPT-4 with a prompt asking for invoice date, description, total price, and link.
  • Parses AI response into structured JSON using Structured Output Parser node.
  • Prepares data to append into Google Sheets.
  • Appends invoice details and Drive link as new row in Google Sheets ledger.
  • Marks Gmail message as read to prevent re-processing.

Outputs

  • Organized invoice PDFs in Google Drive.
  • Accurate invoice data rows in Google Sheets.
  • Gmail inbox updated with messages marked read.

Beginner step-by-step: How to build this in n8n

Step 1: Import the workflow

  1. Download the workflow file using the Download button on this page.
  2. Open n8n Editor and click the menu for Import.
  3. Select “Import from File” option and pick the downloaded workflow.

Step 2: Add Credentials and API Keys

  1. Add or update Gmail OAuth2 credentials for email access.
  2. Add Google Drive OAuth2 to upload and manage files.
  3. Add Google Sheets OAuth2 credentials for appending data.
  4. Add OpenAI API Key for GPT-4 model access.

Step 3: Update IDs and settings

  1. In the Set node, update url_to_drive_folder with the Google Drive folder ID to store invoices.
  2. Optionally, change spreadsheet ID and sheet name in Google Sheets node to your invoice ledger.

Step 4: Test the workflow

  1. Send a test unread email with a PDF invoice attachment to your Gmail.
  2. Run the workflow manually or wait for the minute trigger to fire.
  3. Check if PDF uploads, invoice data extracts, and Google Sheets row appends correctly.

Step 5: Activate for production

  1. Turn on the workflow using the Active toggle in n8n Editor.
  2. Monitor workflow run history to catch errors or unexpected results.

For self-host n8n users, consider visiting self-host n8n for setup help.


Customization ideas

  • Change Google Drive folder dynamically in the Set node per client or year.
  • Add more invoice fields by updating the OpenAI prompt and JSON schema for extraction.
  • Support other file types by adjusting upload node to accept DOCX, images, and add OCR if needed.
  • Add Slack notifications after Google Sheets node to alert finance staff on new invoices.
  • Adapt OpenAI prompt language for invoices in different languages.

Problem spots and fixes

  • If the HTTP Upload PDF to Drive node fails with 403 Forbidden, re-check Google Drive OAuth2 credentials have correct permissions and are active.
  • If AI extraction returns empty data, check if PDF text is readable (not scanned image). Add OCR step if needed.
  • If workflow reprocesses same email, verify Gmail node marks emails as read properly after processing. Validate Gmail filters for unread.

Summary of results

✓ Saves 2-3 hours daily by automating invoice handling.
✓ Removes errors from manual invoice data entry.
✓ Files invoices neatly in Google Drive with clear names.
✓ Records invoice details automatically in Google Sheets.
✓ Ensures emails are marked read to avoid duplicates.
✓ Makes finance workflow faster and more reliable.


Automate Gmail invoices with n8n and Google Drive

Visit through Desktop to Interact with the Workflow.

Frequently Asked Questions

No. This workflow relies on the Gmail Trigger node with OAuth2, so using another email service requires different triggers and authentication nodes.
No. The prompt used is short and uses few tokens per email, but monitoring OpenAI usage is recommended.
Failing uploads often happen when Google Drive OAuth2 credentials are invalid, expired, or lack proper permissions.
The workflow marks Gmail messages as read after processing. Ensuring this step succeeds stops duplicate runs on the same email.

Promoted by BULDRR AI

Related Workflows

Automate Twist Channel Creation and Messaging with n8n

This workflow automates creating and updating a channel in Twist and sending a personalized message to specific users. It eliminates manual setup errors and saves time managing Twist communications.

Automate Ideogram Image Generation with Google Sheets & Gmail

This workflow automates graphic design image generation via Ideogram AI, storing image data in Google Sheets and Google Drive, with email alerts via Gmail. It saves designers hours by automating image creation, remixing, review, and record-keeping.

Automate IT Support with Slack and OpenAI in n8n

Streamline IT support by automating Slack message handling using n8n and OpenAI. This workflow handles Slack DMs, filters bots, queries a Confluence knowledge base, and delivers AI-generated responses, improving support efficiency and response time.

Automate Crypto Analysis with CoinMarketCap & n8n AI Agent

Discover how this unique n8n workflow leverages CoinMarketCap’s multi-agent AI to deliver precise, real-time cryptocurrency insights directly via Telegram. Manage crypto data analysis efficiently with automated multi-source API integration.

Automate Gumroad to Beehiiv Subscriber Sync with n8n

Learn how to automatically add new Gumroad sales customers as Beehiiv newsletter subscribers using n8n automation. This workflow saves time by syncing sales data to Google Sheets CRM and notifying your Telegram channel instantly.

Generate On-Brand Blog Articles Using n8n and OpenAI

This workflow automates the creation of on-brand blog articles by analyzing existing company content using n8n and OpenAI. It extracts article structures and brand voice to produce consistent draft articles, saving significant content creation time.
1:1 Free Strategy Session
Your competitors are already automating. Are you still paying for it manually?

Do you want to adopt AI Automation?

Every hour your team does repetitive work, you're burning real money.
While you wait, faster businesses are cutting costs and moving quicker.
AI and automations aren't the future anymore — they're the present.

Book a live 1-on-1 session where we show you exactly which of your daily tasks can be automated — and what it’s costing you not to.