Automate Gmail PDF Invoice Sorting & Upload to Google Drive

Save hours by automating the classification and upload of PDF invoices and receipts from Gmail to Google Drive using n8n and OpenAI. This workflow intelligently identifies relevant documents and organizes them into dated folders with optional email forwarding, reducing manual work and errors.
openAi
googleDrive
gmail
+10
Workflow Identifier: 2323
NODES in Use: openAi, set, code, noOp, if, merge, googleDrive, webhook, respondToWebhook, gmail, readPDF, filter, stickyNote

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 Automation Does

This workflow looks at Gmail emails in a date range and finds PDF attachments that are receipts or invoices for business costs.
It reads the text in PDFs, asks OpenAI if they match the kind of receipt or invoice needed, and then saves those PDFs in a dated folder on Google Drive.
You can also choose to send the found PDFs by email to an accountant automatically.
This stops wasting lot of time searching and sorting files manually.
You get organized documents saved and shared without any manual work.


Inputs, Processing Steps, and Output

Inputs

  • Webhook POST with JSON data containing startDate, endDate, and optional sendEmail boolean.
  • Gmail emails that have attachments within those dates.

Processing Steps

  1. Retrieve all emails with attachments from Gmail filtered by the date range.
  2. Ignore non-PDF attachments.
  3. Extract text from each PDF attachment.
  4. Check if PDF text length is within OpenAI token limits.
  5. Send PDF text and filename to OpenAI GPT-4.1 Mini to confirm if it is a valid receipt or invoice.
  6. Merge OpenAI response with original PDF data.
  7. Filter only PDFs classified as “true” (matched documents).
  8. Create a Google Drive folder named with the start date, like “invoices_YYYY-MM-DD”.
  9. Upload all matched PDFs into this folder.
  10. If sendEmail is true, gather all matched PDFs and email them to a predefined recipient.

Output

  • Folder with the matched PDFs uploaded to Google Drive.
  • Optional email sent with all matched PDFs attached.

Who Should Use This Workflow

This automation fits users who receive many invoices and receipts by Gmail and want to spend less time searching and downloading PDFs.
Small business owners, freelancers, or accountants can benefit.
It works for people without deep technical skills but some familiarity with n8n and OAuth credentials.


Tools and Services Used

  • Gmail API: To fetch emails and attachments.
  • Google Drive API: To create folders and upload PDF files.
  • OpenAI GPT-4.1 Mini model: To classify PDFs as receipts or invoices.
  • n8n platform: Workflow automation and integrations.

Beginner Step-by-Step: How to Use This Workflow in n8n

Download and Import Workflow

  1. Click the Download button on this document page to get the workflow file.
  2. Open your n8n editor.
  3. Choose Import from File in the top menu.
  4. Select the downloaded workflow file to add it.

Configure Credentials and Parameters

  1. Add Gmail and Google Drive OAuth credentials if missing.
  2. Insert the OpenAI API Key in the OpenAI node credentials section.
  3. Update folder IDs or email addresses if the preset ones do not fit your accounts or recipients.
  4. Check the Configure node for correct parameters like token sizes and matching keywords.

Test the Workflow

  1. Send a test POST request to the webhook URL, including JSON like below:
{
  "startDate": "2024-01-01",
  "endDate": "2024-01-31",
  "sendEmail": true
}

Make sure the date range covers emails with PDF attachments.

Activate for Production

  1. Turn on the workflow toggle in n8n.
  2. Use the webhook URL to trigger the automation when needed.

If self hosting n8n, consider checking self-host n8n for setup tips.


Customization Ideas

  • Change the keyword phrase in the Configure node to detect different document types like “contracts” or “proposals”.
  • Update recipient email addresses for sending the matched PDFs.
  • Modify token size limits to fit longer or shorter documents to control OpenAI costs.
  • Send webhook parameter sendEmail=false to skip email sending and only upload to Google Drive.
  • Add extra filters in the optional filter node to select emails by sender, subject keywords, or labels.

Troubleshooting

  • OpenAI API key error: Check API key setting in OpenAI node has correct key and permission.
  • No emails or attachments: Confirm Gmail OAuth scopes allow full access. Check filters and date ranges.
  • Incorrect Google Drive Upload folder: Verify Create folder node outputs folder ID used in upload node.
  • PDF text extraction errors: Large PDFs may cause issues; consider raising token limits or skipping large files.

Pre-Production Checklist

  • Confirm Google Drive credentials and test folder creation.
  • Validate OpenAI API key by running sample text classification.
  • Send test webhook request to check email retrieval and PDF handling.
  • Ensure Gmail inbox has emails with PDF attachments for the test dates.
  • Adjust token size values if necessary.
  • Test email option on and off.

Summary

✓ Automates finding and sorting business receipts and invoices from Gmail.
✓ Saves time by uploading only matched PDFs to Google Drive.
✓ Optionally sends bundles of PDFs by email to accounting.
✓ Reduces manual errors and keeps documents organized by date.
✓ Easy to use once imported and configured in n8n.

Frequently Asked Questions

This workflow is built specifically for Gmail using Gmail nodes. Other email providers may require custom API integration.
Token usage depends on the number and length of PDF texts processed. Adjust token size limits to control costs.
Data stays within the connected services and the n8n environment. Use secure credentials and encrypted connections.
Yes, as long as n8n plan limits and API quotas allow. Batch triggering may help with very large workloads.

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