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
Automate Gmail PDF invoices with n8n and OpenAI

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

Learn how to Build this Workflow with AI:

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.

Automate Gmail PDF invoices with n8n and OpenAI

Visit through Desktop to Interact with the Workflow.

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 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.