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

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

Learn how to Build this Workflow with AI:

Visit through Desktop for Best experience

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.


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 Viral UGC Video Creation Using n8n + Degaus (Beginner-Friendly Guide)

Learn how to automate viral UGC video creation using n8n, AI prompts, and Degaus. This beginner-friendly guide shows how to import, configure, and run the workflow without technical complexity.
Form Trigger
Google Sheets
Gmail
+37
Free

AI SEO Blog Writer Automation Workflows in n8n

A complete beginner guide to building an AI SEO blog writer automation using n8n.
AI Agent
Google Sheets
httpRequest
+5
Free

Automate CrowdStrike Alerts with VirusTotal, Jira & Slack

This workflow automates processing of CrowdStrike detections by enriching threat data via VirusTotal, creating Jira tickets for incident tracking, and notifying teams on Slack for quick response. Save hours daily by transforming complex threat data into actionable alerts effortlessly.
scheduleTrigger
httpRequest
jira
+5
Free

Automate Telegram Invoices to Notion with AI Summaries & Reports

Save hours on financial tracking by automating invoice extraction from Telegram photos to Notion using Google Gemini AI. This workflow extracts data, records transactions, and generates detailed spending reports with charts sent on schedule via Telegram.
lmChatGoogleGemini
telegramTrigger
notion
+9
Free

Automate Email Replies with n8n and AI-Powered Summarization

Save hours managing your inbox with this n8n workflow that uses IMAP email triggers, AI summarization, and vector search to draft concise replies requiring minimal review. Automate business email processing efficiently with AI guidance and Gmail integration.
emailReadImap
vectorStoreQdrant
emailSend
+12
Free

Automate Email Campaigns Using n8n with Gmail & Google Sheets

This n8n workflow automates personalized email outreach campaigns by integrating Gmail and Google Sheets, saving hours of manual follow-up work and reducing errors in email sequences. It ensures timely follow-ups based on previous email interactions, optimizing communication efficiency.
googleSheets
gmail
code
+5
Free