Automatic Invoice OCR and Data Extraction to Spreadsheet - n8n Workflow

Automate receipt and invoice data entry using AI OCR. This n8n workflow supports Google Drive, Gmail, and Telegram triggers, converting document images into structured data saved directly to Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Finance departments aiming to reduce manual expense entry.

  • Small business owners needing to automatically track receipts.

  • Technical users seeking advanced, multi-channel n8n templates for document processing.

  • Developers interested in integrating powerful AI models like Gemini/Google's API with an n8n workflow.

Overview

Manual entry of expense reports and invoice data is tedious and error-prone. This robust n8n workflow solves this by providing a unified, automated pipeline for capturing receipt images or files from three different sources: Google Drive uploads, Gmail attachments, or images sent via Telegram. Once triggered, the n8n automation processes the binary file, uses a specialized AI (via the HTTP Request n8n node, configured for Gemini) for Optical Character Recognition (OCR), extracts key fields like date, vendor, and amount, and then cleanly inserts this structured data into a Google Sheet. This powerful n8n template demonstrates advanced file handling, conditional logic, and external API integration, making it a highly valuable asset for any user running n8n.

How it Works

This comprehensive n8n workflow begins with one of three potential n8n trigger nodes, ensuring flexible input for expense documents.


  1. Input Trigger: Files can be picked up immediately via the Google Drive Trigger New Files n8n trigger. Alternatively, the Gmail Trigger handles incoming email attachments, and the Telegram Trigger captures images sent to a bot.

  2. File Preparation (Gmail/Telegram): For Gmail and Telegram inputs, the workflow iterates through the items, creates a unique file name using a Code n8n node, and saves the binary file into Google Drive using a Google Drive n8n node. This staging ensures consistency.

  3. OCR Processing Start: The core OCR process is initiated by fetching the file via the Google Drive Get Receipt n8n node (used by the Drive trigger flow).

  4. Base64 Encoding: The Move file to base64 string n8n node converts the binary receipt file into a base64 string format. This is a crucial preparation step required before submitting the image data alongside the extraction prompt to the AI service.

  5. AI Extraction: The Prompt Set n8n node configures the multi-modal prompt, incorporating the base64 string. The Gemini API HTTP Request n8n node sends this request for processing. The AI performs the OCR and returns the extracted invoice data as a structured JSON object.

  6. Data Structuring: Subsequent n8n node steps (JSON to string and Parse string Code n8n node) are used to clean, validate, and structure the extracted data into rows and columns suitable for the target spreadsheet.

  7. Final Logging: The structured data is finally appended to a specified spreadsheet using the Add to Google Sheets n8n node. Flow control nodes (like the Wait n8n node) ensure proper sequential processing throughout this complex n8n workflow.

Installation Guide


  1. Import: Copy the provided n8n workflow JSON and import it into your n8n instance.

  2. Credentials: You must set up the following credentials:

Google Drive: Connect your Google Drive credentials (required for saving files and fetching data).
Gmail: Connect your Gmail account for the Gmail Trigger n8n node.
Telegram: Connect your Telegram Bot API credentials for the Telegram Trigger n8n node.
External API (Gemini): Configure the HTTP Request n8n node ('Gemini API') with the required API key and endpoint for your chosen AI OCR service (e.g., Google's Gemini API).
* Google Sheets: Connect Google Sheets credentials and configure the spreadsheet ID and sheet name in the 'Add to Google Sheets' n8n node.

  1. Activation: Activate the n8n workflow to enable the n8n trigger nodes to start listening for new events.

Node Details

Google Drive Trigger New Files: An n8n trigger that starts the workflow when a new file is uploaded to a monitored Google Drive folder.
Gmail Trigger: An n8n trigger designed to start the workflow upon receiving emails matching specified criteria (e.g., subject line or sender) and handles attachments.
Telegram Trigger Image: An n8n trigger that captures images sent via a Telegram bot, enabling mobile expense capture.
Google Drive Save Files / Google Save Files 2: These Google Drive n8n nodes save the attachments/images received from Gmail and Telegram into Google Drive, preparing them for the central processing path.
Move file to base64 string: A core n8n node essential for converting the binary file received from Drive into a base64 encoded string, which is necessary for multi-modal API submission.
Gemini API (HTTP Request): This powerful n8n node handles the communication with the external AI service. It submits the base64 encoded image and the necessary prompt for OCR and structured data extraction.
Parse string (Code): A Code n8n node used to perform final transformation and ensure the extracted data (which often arrives as a stringified JSON object from the AI) is correctly parsed into a proper JSON object for subsequent steps in the n8n workflow.
Add to Google Sheets: The final action n8n node which appends the successfully extracted and structured data as a new row in the designated Google Sheet.

Related n8n Workflows

Paid

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

A Growth Hacker, Digital Marketer & AI Automation Builder with 10+ years of experience in Digital Marketing & Workflow Automation. Based in Helsinki, Finland. For questions about my templates and customization, contact me at: [email protected]

Featured*