← All N8N workflows
AI & researchCodeFilterGmailGoogle DriveIf

Gmail PDF Invoice/Receipt Classifier & Google Drive Uploader (via n8n & OpenAI)

Configured with Filter, Gmail, Google Drive, Open Ai, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
AI & modelsOpenAIOpen AiTransformConfigureEdit FieldsCodeIterate over emailattachmentsCodeRoutingNot a PDFNo OpRoutingIs text within tokenlimit?IfTransformMergeMergeRoutingIs matchedIfFiles / mediaUpload file to folderGoogle DriveTriggerWebhookWebhookWeb / APIRespond to WebhookRespond To WebhookFiles / mediaCreate folderGoogle DriveCodeAggregate attachmentsCodeRoutingSend email withinvoices?IfMessagingSend to my accountantGmailMessagingGet emails withattachmentsGmailFiles / mediaRead PDF emailattachmentsRead PdfRoutingIs attachment a PDF?IfRoutingOptional filter foremailsFilter

Node categories in this workflow

  • AI & models
  • Transform
  • Code
  • Routing
  • Files / media
  • Trigger
  • Web / API
  • Messaging

Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.

Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.

How it works

The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.

Workflow node names, types, and operations
NodeCategoryTypeOperation
OpenAIAI & modelsOpen AiSee node parameters
ConfigureTransformEdit FieldsSee node parameters
Iterate over email attachmentsCodeCodeSee node parameters
Not a PDFRoutingNo OpSee node parameters
Is text within token limit?RoutingIfSee node parameters
MergeTransformMergeSee node parameters
Is matchedRoutingIfSee node parameters
Upload file to folderFiles / mediaGoogle DriveSee node parameters
WebhookTriggerWebhookSee node parameters
Respond to WebhookWeb / APIRespond To WebhookSee node parameters
Create folderFiles / mediaGoogle Drivefolder
Aggregate attachmentsCodeCodeSee node parameters
Send email with invoices?RoutingIfSee node parameters
Send to my accountantMessagingGmailSee node parameters
Get emails with attachmentsMessagingGmailgetAll
Read PDF email attachmentsFiles / mediaRead PdfSee node parameters
Is attachment a PDF?RoutingIfSee node parameters
Optional filter for emailsRoutingFilterSee node parameters

Setup

  1. Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
  2. Connect your own credentials through n8n’s credential store. Replace REPLACE_WITH_* values with your resource identifiers.
  3. Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
  4. Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.

Requirements

An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.

Credential types declared in the source

  • gmailOAuth2
  • googleDriveOAuth2Api
  • httpHeaderAuth
  • openAiApi

Workflow notes

Gmail PDF Invoice/Receipt Classifier & Google Drive Uploader (via n8n & OpenAI)

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

Parameters

Parameters

  • maxTokenSize (Number)

    • Limits PDF text length (estimated input tokens) sent to OpenAI for classification. Prevents errors/high costs on long documents.
    • Default: 8000
  • replyTokenSize (Number)

    • Reserves tokens for OpenAI's reply ('true'/'false'). Ensures total tokens stay within limits.
    • Default: 50
  • Match on (String)

    • The keyword/phrase OpenAI uses to identify the desired document type (e.g., "receipt or invoice", "contract"). Defines what you're searching for.
    • Default: "receipt or invoice"
  • sendInvoicesTo (String)

    • Recipient email address for the final collection of matched PDFs. Used only if sendEmail is true.
    • Example: "user@example.com"
  • sendEmail (Boolean)

    • Turns the final email step on (true) or off (false). Set via the initial webhook trigger. If false, files are only uploaded to Drive.
    • Example: true or false
Gmail PDF Invoice/Receipt Classifier & Google Drive Uploader (via n8n & OpenAI)

Gmail PDF Invoice/Receipt Classifier & Google Drive Uploader (via n8n & OpenAI)

Purpose and structure

This folder contains the Gmail PDF Invoice/Receipt Classifier & Google Drive Uploader (via n8n & OpenAI) workflow. Its executable nodes use code, filter, gmail, googleDrive, if, merge, noOp, openAi, readPDF, respondToWebhook, set, webhook. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.

Setup

Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.

Entry points

Webhook

Verification

Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.

Attribution

https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Webhook/0892_Webhook_Code_Create_Webhook.json MIT; preserve source notices.

More in AI & research