Library / Documents, PDF & OCR
Documents, PDF & OCR
Classify Gmail PDF Invoices with OpenAI into Drive
When an email with PDF attachments arrives, OpenAI checks whether each is an invoice or receipt and uploads matches to a Google Drive folder.
What it does
## Gmail PDF Invoice/Receipt Classifier & Google Drive Uploader (via n8n & OpenAI) _DISCLAIMER: AI classification isn't perfect. Always double-check that the correct documents were identified and uploaded._ This n8n workflow, triggered via a webhook, scans your Gmail for emails within a specified date range, extracts PDF attachments, and uses OpenAI to determine if each PDF matches a defined category (defaulting to "receipt or invoice"). Matched PDFs are then uploaded to a uniquely named Google Drive folder based on the date range. You can customize the classification term (e.g., change "receipt or invoice" to "contract") and optionally have the workflow email the collected PDFs to a specified address. ### How it works 1. Triggers via a Webhook receiving a start date, end date, and an optional flag to send an email. 2. Creates a dated folder in Google Drive (e.g., invoices_YYYY-MM-DD_YYYY-MM-DD). 3. Fetches emails with attachments from Gmail within the specified date range. 4. Iterates through each attachment, filtering specifically for PDF files. 5. Extracts text from each PDF (skipping if the text exceeds token limits set in the Configure node). 6. Uses the OpenAI node to ask if the PDF content and filename look like the item defined in the Configure node's "Match on" field (e.g., "receipt or invoice"). 7. If OpenAI responds with "true", the original PDF file is uploaded to the Google Drive folder created in step 2. 8. If the initial webhook request included the flag to send an email, it aggregates all successfully matched PDFs and sends them via Gmail to the address specified in the Configure node. Workflow written by [Tom]({{ $env.WEBHOOK_URL }}
The steps
- OpenAI
- Configure
- Iterate over email attachments
- Not a PDF
- Is text within token limit?
- Merge
- Is matched
- Upload file to folder
- Webhook
- Respond to Webhook
- Create folder
- Aggregate attachments
- Send email with invoices?
- Send to my accountant
40 steps in total.
Similar automations
Documents, PDF & OCRClassify Gmail Invoices and Receipts with OpenAI into Drive18 stepsContent Writing & GenerationClassify and Summarize WeChat Articles into Sheets and Notion21 stepsEmail AutomationClassify Outlook Email Attachments with Gemini into Excel39 stepsDocuments, PDF & OCRSave matching Gmail PDF attachments to Google Drive using OpenAI17 steps