AI-Powered Invoice Processing from Gmail to Google Sheets and Drive - n8n Workflow

Use this powerful n8n workflow template to automatically process invoice attachments received via Gmail. Upload PDFs to Google Drive, leverage OpenAI for structured data extraction, and log all details accurately in Google Sheets using specialized n8n nodes.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Accounting and Finance Professionals seeking to automate tedious invoice reconciliation.
Small Business Owners needing an efficient, error-free method to track expenses.
n8n automation specialists looking for advanced n8n templates integrating AI and core logic nodes.
Teams wanting to eliminate manual data entry from PDF documents using an intelligent n8n workflow.

Overview

Manually processing invoices from email attachments is time-consuming and prone to errors. This specialized n8n workflow solves this by creating a fully automated pipeline. The moment an invoice hits your designated inbox, the n8n trigger captures it. The PDF is securely stored in Google Drive, renamed for organizational clarity, and then subjected to AI-powered data extraction using the OpenAI n8n node. By utilizing a Structured Output Parser, this n8n workflow guarantees clean, formatted data ready for insertion into Google Sheets, drastically improving operational efficiency and data accuracy. This particular n8n template demonstrates the high potential of combining file operations with advanced large language models within the n8n automation environment.

How it Works

This n8n workflow begins with the Gmail Trigger node, which constantly polls your specified inbox for new, unread emails and automatically downloads any attachments.


  1. Filtering and Setup: An initial Setup n8n node defines the target Google Drive folder ID. The subsequent IF n8n node (Only invoice mails with attachments) checks if the email contains attachments or is a multipart message, filtering out irrelevant correspondence.

  2. Storage: The workflow proceeds to upload the binary PDF data directly to Google Drive via an HTTP Request n8n node. It is then renamed using the email subject and the current date (e.g., SupplierNameinvoice2024-01-15.pdf) and moved to the correct specified folder using dedicated Google Drive n8n node actions.

  3. Data Preparation: The file is downloaded back into the n8n workflow environment using a Google Drive n8n node, and the Extract from File n8n node performs Optical Character Recognition (OCR) to convert the PDF content into plain text.

  4. AI Extraction: The core of the automation uses the LangChain LLM Chain n8n node, paired with the gpt-4o OpenAI Model, to apply custom extraction rules to the raw PDF text. This step includes dynamic input, such as creating a hyperlink back to the newly saved file in Google Drive (Fichero).

  5. Structuring Output: The extracted data passes through the Structured Output Parser n8n node, which strictly enforces a specific JSON schema (date, number, string) ensuring reliable data integrity.

  6. Final Logging and Cleanup: The processed and structured data is mapped and then appended directly to the designated Google Sheets ledger using the Append to Reconciliation Sheet n8n node. Finally, the original email is marked as 'Read' using the Gmail n8n node, completing this robust n8n workflow.

Installation Guide

To deploy this comprehensive n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON and paste it into your n8n canvas using the 'New' -> 'Import from JSON' option.

  2. Configure Credentials: You require four sets of credentials for this n8n template to function:

Gmail OAuth2: Connect your Gmail account to enable the Gmail n8n trigger and marking emails as read.
Google Drive OAuth2 API: This is needed for uploading, renaming, and moving files within Google Drive.
Google Sheets OAuth2 API: Required for appending data to your reconciliation spreadsheet.
OpenAI API: Necessary for the advanced AI data extraction capabilities of the n8n workflow.

  1. Setup Node Configuration: In the Setup1 n8n node, replace the placeholder urltodrive_folder value with the actual folder ID where you want to store your incoming invoices.

  2. Google Sheets Configuration: In the Append to Reconciliation Sheet n8n node, select your target Google Sheet document and specify the sheet name or GID.

  3. Activate: Set the n8n trigger to 'Active' to start monitoring your inbox.

Node Details

This n8n workflow utilizes several powerful n8n node types:

Gmail Trigger: The essential starting n8n trigger. It is configured to only process unread messages and automatically downloads attachments, ensuring the n8n workflow starts immediately upon invoice arrival.
If n8n node (Only invoice mails with attachments): Implements core logic flow control. Checks for multipart/mixed content-type or if the attachments array is non-empty, directing only relevant emails down the processing path.
HTTP Request n8n node (Upload PDF to Drive1): Used for efficiently uploading the binary PDF data directly to the Google Drive API, a key step in this n8n workflow.
Google Drive n8n node: Used for subsequent file operations, specifically update (renaming the file using dynamic expressions) and move (placing the file in the designated folder).
Extract from File n8n node: Performs PDF text extraction, converting the visual invoice data into usable text input for the AI n8n node.
LangChain LLM Chain n8n node (Apply Data Extraction Rules): This crucial n8n node defines the extraction logic and prompt. It instructs the large language model (LLM) to extract structured fields (Date, Price) from the textual invoice data.
Structured Output Parser n8n node: Attached to the LangChain LLM Chain, this ensures the AI output strictly adheres to the defined JSON schema, making the data perfectly ready for Google Sheets.
Google Sheets n8n node (Append to Reconciliation Sheet): The final action n8n node, taking the validated, structured data and appending it to the reconciliation sheet.

Related n8n Workflows

Free

Nodes: 13 Nodes
Updated: December 26 2025
View all

Featured*