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

1. Opening Problem Statement

Meet Laura, an accounts payable clerk at a mid-sized company. Every day, Laura spends hours sifting through her Gmail inbox to find unread invoices sent as PDF attachments. She opens each email, downloads the PDF, manually uploads it to the correct client folder in Google Drive, then types key invoice details into a Google Sheets ledger to keep track of payments. 

This manual process wastes Laura about 2-3 hours daily, risks missing invoices, and often results in occasional human errors when copying invoice data. Invoices sometimes get misfiled or lost, delaying payments and causing accounting headaches.

Laura needs a way to automate this workflow end-to-end to regain her time, reduce errors, and maintain an organized, searchable record of every invoice.

2. What This Automation Does

This powerful n8n workflow listens for new unread emails in Gmail containing invoice attachments. Here’s exactly what happens when it runs:

  • Checks Gmail every minute for unread emails with attachments labeled as invoices.
  • Automatically downloads the PDF invoice attachments.
  • Uploads each PDF directly into a pre-specified Google Drive folder, renaming the files to correspond with the email subject and current date for easy identification.
  • Moves the uploaded files into the correct client folder within Google Drive.
  • Extracts the PDF text content using n8n’s Extract From File node.
  • Uses OpenAI’s GPT-4 model to intelligently parse the invoice details (invoice date, description, total price) from the PDF content.
  • Formats the extracted data with a Structured Output Parser node for clean data insertion.
  • Appends the invoice data along with a hyperlink to the Google Drive file into a Google Sheets reconciliation ledger.
  • Marks the original Gmail email as read, preventing duplicate processing.

This automation saves Laura at least two hours daily, eliminates manual transcription errors, and ensures all invoices are systematically archived and tracked.

3. Prerequisites 

  • n8n account with workflow editing and activation rights. Self-hosting is possible for advanced users.
  • Gmail account with OAuth2 credentials configured in n8n. 
  • Google Drive account and OAuth2 integration to upload and manage PDF files.
  • Google Sheets account with OAuth2 access to append rows to the invoice ledger.
  • OpenAI API key for the GPT-4 language model to extract invoice details from PDFs.

4. Step-by-Step Guide

Step 1: Set up Gmail Trigger
Navigate to n8n Editor → Click + to add a new node → Search and select Gmail Trigger node.
Configure it to trigger every minute and filter for unread messages. Enable attachment download option.
You should see new incoming emails trigger workflow executions.
Common mistake: Forgetting to set filter to unread emails can cause duplicate processing.

Step 2: Add a Set Node to Define Google Drive Folder
Add Set node after Gmail Trigger.
Create a string field named url_to_drive_folder and paste your Google Drive folder ID where invoices should be stored.
Expected: This sets the target folder dynamically for file moves later.
Common mistake: Ensure folder ID is correct or files will not move properly.

Step 3: Filter Emails with Attachments
Insert an If node configured to pass only emails with attachments or where content-type includes ‘multipart/mixed’.
Connect Gmail Trigger to this node.
Expected: Skips emails without attachments.
Common mistake: Incorrect condition logic can skip valid emails with invoices.

Step 4: Upload PDF Attachments to Google Drive
Add an HTTP Request node to upload PDFs.
Configure method as POST to https://www.googleapis.com/upload/drive/v3/files with query param uploadType=media.
Set content-type to binary data and input data field dynamically chosen based on attachment mime type (prefer PDF).
Use Google Drive OAuth2 credentials.
Expected result: PDFs upload successfully and node returns file IDs.
Common mistake: Incorrect binary input field or credential issues cause upload failures.

Step 5: Rename Uploaded File in Google Drive
Use a Google Drive node with operation ‘update’ to rename the new file.
Set File ID from upload node output.
Rename format example: {Email Subject}_invoice_{Current Date}.pdf.
Expected: Uploaded file gets a meaningful name.
Common mistake: Forgetting to reference the new file ID causes rename failure.

Step 6: Move File to Correct Google Drive Folder
Add another Google Drive node configured to move the renamed file to the folder ID set in the Set node.
Expected: Invoice PDFs neatly organized.
Common mistake: Folder ID mismatch leads to misplaced files.

Step 7: Download File from Google Drive for Text Extraction
Add a Google Drive node with operation ‘download’.
Use the file ID from the move node.
Expected: File content available as binary for extraction.
Common mistake: Using wrong file ID breaks extraction step.

Step 8: Extract Text from PDF
Add Extract From File node with operation set to PDF.
Pass binary data from downloaded file.
Expected: Text content of invoice ready for processing.
Common mistake: If PDF is scanned image rather than text PDF, node may fail or return empty text.

Step 9: Use OpenAI GPT-4 Model to Extract Invoice Details
Add OpenAI Model node (n8n-nodes-langchain.lmOpenAi).
Configure model to GPT-4o with temperature 0 for consistent output.
Create prompt with XML tags enclosing extracted invoice text, requesting date, description, total price, and a hyperlink to the Drive file.
Expected: AI returns structured invoice data.
Common mistake: Invalid or unclear prompt results in poor extraction.

Step 10: Parse AI Output into Structured JSON
Insert Structured Output Parser node.
Define JSON schema for invoice date, description, total price, and file link.
Expected: Clean JSON data for direct use.
Common mistake: Schema mismatch with AI output causes errors.

Step 11: Format Data for Google Sheets Input
Use Set node in raw JSON mode to extract AI output.
Expected: Data ready to append.
Common mistake: Not mapping output correctly leads to empty rows.

Step 12: Append Extracted Invoice Data to Google Sheets
Add Google Sheets node with append operation.
Map columns to invoice date, description, total price, and link.
Expected: Invoice details logged automatically.
Common mistake: Wrong Spreadsheet ID or Sheet Name causes failures.

Step 13: Mark Gmail Message as Read
Finally, use Gmail node to mark the processed email as read.
Use message ID from the Gmail Trigger node.
Expected: Workflow wont reprocess same emails.
Common mistake: Using incorrect message ID repeats processing.

5. Customizations 

  • Change folder destination: In the Set1 node, update url_to_drive_folder to save invoices to a different Drive folder for each client or year.
  • Add more invoice fields: Modify Apply Data Extraction Rules prompt and Structured Output Parser schema to extract additional invoice data like tax, payment terms.
  • Support other attachment types: Adjust Upload PDF to Drive1 HTTP node to handle DOCX or image invoices by expanding mime type checks and extraction.
  • Automate Slack notifications: Add a Slack node after Google Sheets to notify finance team of new invoices added.
  • Multi-language extraction: Adapt OpenAI prompt to handle invoices in other languages by changing instructions.

6. Troubleshooting 

Problem: “Upload PDF to Drive1” HTTP Request node fails with 403 Forbidden.
Cause: Google Drive OAuth2 credentials incorrect or expired.
Solution: Re-authenticate Google Drive credentials in n8n and ensure API permissions are granted.

Problem: AI extraction returns empty fields.
Cause: Extracted text from PDF is empty or scanner image only.
Solution: Verify PDF text can be read. Use OCR preprocessing if needed before extraction.

Problem: Workflow processes same email multiple times.
Cause: Gmail Trigger not marking emails as read timely.
Solution: Confirm Gmail node marks email read after processing and check Gmail filters.

7. Pre-Production Checklist 

  • Verify Gmail OAuth2 credentials are active and emails can be read.
  • Confirm Google Drive folder ID used in Set1 node is correct and accessible.
  • Test workflow with a sample unread invoice email with PDF attachment.
  • Check OpenAI API key validity and that GPT-4o model is accessible.
  • Confirm Google Sheets ID and sheet name correspond to your invoice ledger.
  • Review logs for any errors and perform manual data verification initially.

8. Deployment Guide

Activate the workflow by toggling the Active switch in n8n Editor.
Monitor execution through n8n’s workflow run history and recent executions.
Set up alerts in n8n for failed executions if desired.
Regularly review Google Sheets and Drive for expected invoice entries and files.
Backup your Google Sheets data periodically.

9. FAQs

Q: Can I use another email provider instead of Gmail?
A: This workflow relies on the Gmail Trigger node with OAuth2, so switching to another provider requires different trigger and authentication nodes.

Q: Does the OpenAI usage consume many credits?
A: The invoice data extraction prompt is concise, so usage per email is minimal, but monitor your OpenAI quota accordingly.

Q: Is my invoice data secure?
A: All data stays within your Google and OpenAI accounts with OAuth2 secured connections. Avoid sharing credentials publicly.

10. Conclusion

By setting up this n8n workflow, you have automated the tedious process of managing invoice emails in Gmail. You saved hours each day by automatically downloading invoice PDFs, organizing them in Google Drive, extracting key invoice data with AI, and logging everything into Google Sheets. This eliminates manual errors and keeps your accounting records accurate and up to date.

Next steps? Consider building automations to notify your team on Slack for new invoices or integrating payment tracking systems. Keep exploring how n8n and AI can reduce your workload and improve your finance operations.

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 in n8n (Beginner Guide)

A complete beginner guide to building an AI-powered 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