AI-Powered Invoice Data Extraction from Email to Google Sheets - n8n Workflow

Automate financial data entry using an n8n workflow. Extract invoice details from Gmail PDF attachments using GPT-4o AI and save structured data to Google Sheets instantly.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Accountants and Bookkeepers needing to eliminate manual invoice data entry.
Finance teams automating accounts payable processing.
Small businesses seeking robust invoice tracking and organization.
Users looking for advanced n8n templates integrating AI for document analysis.

Overview

This sophisticated n8n workflow solves the tedious problem of manual invoice data entry. By leveraging the power of an advanced AI model (GPT-4o via an n8n node), it monitors a specified Gmail label for incoming invoices. Once a PDF attachment is detected, the n8n workflow automatically extracts raw text, sends it to the AI Agent for intelligent parsing into structured JSON, creates a dedicated Google Sheet for the records, and moves the resulting sheet to a designated Google Drive folder. This complete end-to-end automation transforms unstructured document data into actionable, organized financial records, making this n8n template invaluable for efficient financial operations. This is a perfect example of a robust n8n workflow utilizing specialized n8n nodes for complex tasks.

How it Works


  1. The process begins with the Gmail Trigger n8n node, which continuously polls a pre-defined email label (e.g., “Invoice Processing”) for new messages, ensuring attachments are downloaded.

  2. The Attachment Verification n8n node filters the items, proceeding only if a binary PDF attachment is present.

  3. The Extract Invoice data n8n node converts the binary PDF attachment into readable text data, preparing it for AI consumption.

  4. The extracted text is passed to the Invoice AI Agent n8n node, which utilizes the OpenAI Chat Model (GPT-4o-mini). This powerful combination processes the text using a strict financial system prompt to extract over 25 fields (like invoice number, line items, taxes, totals, and company details) and formats the output as a guaranteed JSON object.

  5. A new Google Sheet is created with the Create blank spreadsheet n8n node, titled dynamically based on the current timestamp.

  6. The Move spreadsheet in invoice folder n8n node then organizes the newly created sheet by moving it to a specific “invoices” folder within Google Drive.

  7. The Preparing Final data custom code n8n node parses the structured AI output (which is currently a JSON string) into a ready-to-use JSON object for Google Sheets.

  8. Finally, the Final Spreadsheet with Invoice data n8n node appends the highly structured invoice data to the relevant sheet, completing the n8n workflow and providing perfectly formatted data.

Installation Guide

Import the n8n workflow JSON file into your n8n instance.
Credentials Setup: You must configure four sets of credentials for this n8n template:
Gmail OAuth2: For the Gmail Trigger to access and monitor labeled emails.
OpenAI API Key: For the OpenAI Chat Model and Invoice AI Agent nodes to perform data extraction using GPT-4o.
Google Sheets OAuth2: To enable the creation and population of new spreadsheets.
Google Drive OAuth2: To allow the workflow to move and organize the created spreadsheets in your Drive.
Gmail Label Configuration: Ensure the Gmail Trigger n8n node is configured to monitor the correct label ID designated for your incoming invoice emails.
Google Drive Folder: Verify and update the Folder ID parameter in the Move spreadsheet in invoice folder n8n node to match your desired archive folder in Google Drive.


  • Activate the n8n trigger to start monitoring your inbox.

Node Details

Gmail Trigger: This essential n8n trigger starts the process. It monitors a specified Gmail label, downloading all attachments to initiate the n8n workflow.
Extract Invoice data (Extract File n8n node): Converts the binary PDF invoice file into raw, readable text, which is the input for the AI agent.
Invoice AI Agent (Langchain Agent n8n node): The intelligence engine of the n8n workflow. It uses a custom system message to guide the GPT model to extract detailed structured data fields (like gstregistrationno, subtotal, and line items) from the extracted text, ensuring consistency across the n8n template.
OpenAI Chat Model (n8n node): Provides the GPT-4o-mini backend, configured to force a JSON response format. This is critical for reliable downstream data processing within this n8n template.
Preparing Final data (Code n8n node): A critical custom code n8n node that uses JSON.parse to convert the string output from the AI into a structured JSON array suitable for writing to Google Sheets.
Create blank spreadsheet (Google Sheets n8n node): Creates the required destination document for the structured financial data.


  • Final Spreadsheet with Invoice data (Google Sheets n8n node): Appends the fully parsed invoice data, adhering to a defined column schema, into the designated sheet.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by

Building AI Agents and Automations | Growth Marketer | Entrepreneur | Book Author & Podcast Host

Featured*