Skip to content
NEWMarketplace and the trig8n Agent: sell what you build, and get plans and changes that are tested before you see them. See what is new

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

  1. OpenAI
  2. Configure
  3. Iterate over email attachments
  4. Not a PDF
  5. Is text within token limit?
  6. Merge
  7. Is matched
  8. Upload file to folder
  9. Webhook
  10. Respond to Webhook
  11. Create folder
  12. Aggregate attachments
  13. Send email with invoices?
  14. Send to my accountant

40 steps in total.

Similar automations