Automate document classification using this n8n workflow. Extract PDF invoices from Gmail, classify them with OpenAI, upload matched files to Google Drive, and optionally email them.
Download this n8n workflow template and start using it instantly.
Small Business Owners/Freelancers: Needing automated expense tracking and filing of receipts and invoices.
Accountants/Bookkeepers: Requiring a streamlined method to collect and sort client documents based on defined criteria.
Automation Enthusiasts: Looking for powerful n8n templates that combine email automation, AI integration, and cloud storage operations.
Technical Users: Who need to leverage the power of the OpenAI n8n node for document intelligence.
Managing digital receipts and invoices received via email is a tedious task. This comprehensive n8n workflow solves this by introducing AI-powered classification directly into your document pipeline.
Starting with a simple webhook n8n trigger, the system fetches all relevant emails from Gmail within a user-defined date range, isolates PDF attachments, and utilizes the OpenAI n8n node (specifically GPT-4.1-mini in this configuration) to determine if the document matches a user-defined business cost criteria (e.g., 'software engineering business cost'). Documents that pass classification are automatically uploaded to a dedicated, dated folder in Google Drive. This powerful n8n template ensures that your filing is accurate, fast, and highly customizable.
This automation is initiated by an external system calling the Webhook n8n trigger, providing startDate and endDate parameters.
Webhook is received, and a unique, dated folder is immediately created in Google Drive using the Create folder n8n node. Concurrently, the Respond to Webhook n8n node sends an immediate 202 status acceptance back to the calling service, ensuring fast execution.Configure n8n node sets critical variables, including the maximum token size for OpenAI input (maxTokenSize) and the classification term (Match on).Get emails with attachments n8n node scans Gmail for all emails containing attachments within the defined date range. A subsequent filter further refines the email list.Iterate over email attachments Code n8n node separates all binary attachments into individual items. The Is attachment a PDF? n8n node checks the file extension, discarding non-PDF files.Read PDF email attachments n8n node extracts the textual content of the PDF. The Is text within token limit? n8n node acts as a safeguard, preventing large documents from exceeding OpenAI's context limits, thus saving costs.OpenAI n8n node receives the PDF text and filename. It uses the custom prompt to classify the document against the 'Match on' criteria, returning a simple 'true' or 'false'.Is matched n8n node checks if the result is 'true'. If confirmed, the original binary file is uploaded to Google Drive using the Upload file to folder n8n node.Send email with invoices? n8n node checks the initial sendEmail flag. If true, the Aggregate attachments Code n8n node compiles all successfully classified PDFs into one item, which is then sent via the Send to my accountant Gmail n8n node to the specified recipient.To use this n8n workflow, follow these steps:
OpenAI n8n node to enable AI classification.Configure Set n8n node:Match on field to specify the exact document type you are searching for (e.g., "receipt or invoice that can be considered a software engineering business cost").Google Drive folder to upload matched PDFs ID (the parent folder where the dated subfolders will be created).sendInvoicesTo with the recipient email (e.g., your accountant).Webhook n8n trigger node to initiate the process externally.This powerful n8n workflow relies on a mix of core logic nodes and external service integrations:
Webhook (n8n trigger): The starting point. Listens for POST requests, expecting parameters like startDate, endDate, and sendEmail to define the search scope and final action.
Gmail (Get emails with attachments): Fetches emails. Uses dynamic expressions to set receivedAfter and receivedBefore based on the data provided by the n8n trigger.
Google Drive (Create folder & Upload file to folder): Manages file storage. It first creates a dynamically named folder (e.g., invoices_YYYY-MM-DD) and then uploads the classified PDF files to that location.
Read PDF email attachments (Read PDF n8n node): Essential for document intelligence. This node extracts raw text from the binary PDF attachments, making the content readable for the subsequent AI step.
OpenAI (n8n node): The core classification engine. It takes the PDF text and filename, uses a specific system prompt, and performs binary classification (true/false) based on the criteria set in the Configure node.
Configure (Set n8n node): Defines crucial variables such as the AI classification criteria (Match on) and token limits (maxTokenSize), demonstrating how to use dynamic configuration within an n8n template.
Use this comprehensive n8n workflow to capture tasks via text or voice message on Telegram, employ Gemini AI for robust data extraction and transcription, and automatically create approved task pages in Notion.

Use this powerful n8n workflow to automate competitor backlink extraction utilizing Bright Data MCP, AI agents, and GPT-4o-mini. Analyze link data and automatically store results in Google Sheets. Find more advanced n8n templates here.

Use this powerful n8n workflow to combine Bright Data web scraping with Google Gemini AI for advanced brand content analysis, summarization, and structured sentiment analysis. Easily extract insights using this n8n template.

Use this powerful n8n workflow to automate B2B lead generation. Extract, enrich, and export unique LinkedIn post commenters to Google Sheets using robust Apify scrapers. Get started with n8n templates today.

Use this n8n workflow to monitor Reddit for specific keywords or subreddits, filter posts by upvotes, and extract the top comments, delivered as a formatted report.

Automate invoice processing using this advanced n8n workflow. Extract data from images or PDFs with Gemini AI, validate required fields, prevent duplicate entries in Google Sheets, and send instant Gmail notifications using a comprehensive n8n node setup.

Software Engineer and Architect for well over 10 years. Chromium project expert. Full Stack beast. Workflow automation enthusiast. Founder of BrowseWiz: in-browser AI assistant and AI agent platform with human in-the-loop.







































