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.
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.
| Node | Category | Type | Operation |
|---|---|---|---|
| OpenAI | AI & models | Open Ai | See node parameters |
| Configure | Transform | Edit Fields | See node parameters |
| Iterate over email attachments | Code | Code | See node parameters |
| Not a PDF | Routing | No Op | See node parameters |
| Is text within token limit? | Routing | If | See node parameters |
| Merge | Transform | Merge | See node parameters |
| Is matched | Routing | If | See node parameters |
| Upload file to folder | Files / media | Google Drive | See node parameters |
| Webhook | Trigger | Webhook | See node parameters |
| Respond to Webhook | Web / API | Respond To Webhook | See node parameters |
| Create folder | Files / media | Google Drive | folder |
| Aggregate attachments | Code | Code | See node parameters |
| Send email with invoices? | Routing | If | See node parameters |
| Send to my accountant | Messaging | Gmail | See node parameters |
| Get emails with attachments | Messaging | Gmail | getAll |
| Read PDF email attachments | Files / media | Read Pdf | See node parameters |
| Is attachment a PDF? | Routing | If | See node parameters |
| Optional filter for emails | Routing | Filter | See node parameters |
Setup
- Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
- Connect your own credentials through n8n’s credential store. Replace
REPLACE_WITH_*values with your resource identifiers. - Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
- 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
gmailOAuth2googleDriveOAuth2ApihttpHeaderAuthopenAiApi
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
- Triggers via a
Webhookreceiving a start date, end date, and an optional flag to send an email. - Creates a dated folder in
Google Drive(e.g.,invoices_YYYY-MM-DD_YYYY-MM-DD). - Fetches emails with attachments from
Gmailwithin the specified date range. - Iterates through each attachment, filtering specifically for
PDFfiles. - Extracts text from each PDF (skipping if the text exceeds token limits set in the
Configurenode). - Uses the
OpenAInode to ask if the PDF content and filename look like the item defined in theConfigurenode's "Match on" field (e.g., "receipt or invoice"). - If OpenAI responds with "true", the original
PDFfile is uploaded to theGoogle Drivefolder created in step 2. - If the initial webhook request included the flag to send an email, it aggregates all successfully matched PDFs and sends them via
Gmailto the address specified in theConfigurenode.
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
sendEmailis true. - Example: "user@example.com"
- Recipient email address for the final collection of matched PDFs. Used only if
-
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:
trueorfalse
- Turns the final email step on (
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.