Automated Invoice Data Extraction using OCR and AI to Google Sheets - n8n Workflow

Use this robust n8n workflow to automatically scan, process, and extract structured financial data from Japanese invoices (PDFs/Images) using OCR.Space and GPT-4o-mini, logging results directly into Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Accounting and Finance professionals looking to eliminate manual invoice data entry.

  • Operations teams requiring automated document processing solutions.

  • Developers searching for advanced n8n templates for combining OCR, LLMs, and cloud storage.

  • Users handling high volumes of Japanese-language financial documents.

Overview

Handling invoices often involves repetitive and error-prone manual data entry. This advanced n8n automation template solves this by providing a hands-off, scheduled solution for invoice processing. The core problem addressed is translating unstructured image or PDF invoice data into clean, structured data for accounting purposes.

This n8n workflow leverages the power of cloud services and AI: Google Drive acts as the input source; OCR.Space extracts raw text from the documents; and finally, the OpenAI n8n node (GPT-4o-mini) enforces a strict JSON schema to extract critical fields like dates, totals, client names, and bank information. The extracted data is then securely and neatly recorded in a target Google Sheet, making this an essential automation for modern back-office operations. This powerful n8n workflow significantly boosts accuracy and efficiency.

How it Works

The entire process starts with a recurring Schedule n8n trigger:


  1. Scheduled Execution: The n8n trigger initiates the workflow weekly to ensure all new invoices are captured.

  2. Drive Discovery: Google Drive n8n nodes sequentially find the designated parent folder and then dynamically identify the current month's subfolder (using a dynamic date expression zoned for Asia/Tokyo).

  3. File Listing and Download: All PDF and image files within the current monthly subfolder are listed. For each file, the Google Drive n8n node downloads the file content as binary data.

  4. OCR Processing: The binary data is sent to the OCR.Space API via an HTTP Request n8n node, specifically configured for Japanese language (jpn) and table extraction, converting the image content into raw text.

  5. Text Cleanup: A Code n8n node cleans the raw OCR output, normalizing line breaks, removing excessive white space, and standardizing currency symbols, preparing it for AI analysis.

  6. AI Structured Extraction: The cleaned text is passed to the OpenAI n8n node. This node uses GPT-4o-mini with a detailed system prompt instructing the model to reconstruct the invoice information and strictly output a predefined JSON format, ensuring data consistency.

  7. Data Parsing: Another Code n8n node safely parses the raw JSON string output from the AI into usable JavaScript objects.

  8. Google Sheets Recording: Finally, the Google Sheets n8n node appends a new row for each successfully processed invoice. It maps the extracted fields (total, dates, bank info, client name, etc.) and includes the original file's PDF link, completing the fully automated n8n workflow.

Installation Guide


  1. Import the n8n template: Copy the provided JSON into your n8n instance using the 'Import Workflow' function.

  2. Google Drive Setup: Set up your Google Drive credential. Ensure the service account has access to the target invoice folders. Configure the queries in the 'Get Parent Folder' and 'Get Monthly Subfolder' n8n nodes to match your folder structure and naming conventions.

  3. OCR.Space Setup: Obtain an API key from OCR.Space. Update the OCR (OCR.Space Parsing) HTTP Request n8n node by replacing ocrapikey> in the header parameters with your actual key.

  4. OpenAI Setup: Configure your OpenAI credential. Ensure the API key is active and has access to GPT-4o-mini (or GPT-4 models).

  5. Google Sheets Setup: Set up your Google Sheets credential. In the 'Append to Google Sheets' n8n node, replace googlesheetid> with the ID of your target accounting ledger sheet.

Node Details

Schedule Trigger (Weekly Scan):
Function: Acts as the starting n8n trigger, initiating the entire data extraction process automatically every week.
Key Configuration: Set to run weekly (in the provided JSON, Monday at 20:00).
Google Drive Nodes (Get Parent Folder, Get Monthly Subfolder, List Files, Download File):
Function: Manages file access, dynamically locating the current month's invoice subfolder, listing relevant PDFs/images, and downloading them as binary files.
Key Configuration: Uses advanced query strings to filter by file type and folder name, using the current date ($now) for month detection.
OCR (OCR.Space Parsing) (HTTP Request n8n node):
Function: Sends the binary invoice file to the external OCR.Space API to perform Optical Character Recognition.
Key Configuration: Uses multipart-form-data to send the binary file; specifies language: jpn (Japanese) and includes the API key in a custom header.
Clean OCR Text (Noise Removal) (Code n8n node):
Function: Pre-processes the raw text output from OCR, crucial for high-quality LLM input. It standardizes line breaks, spaces, and currency symbols.
Key Configuration: Contains custom JavaScript for text normalization using RegEx.
AI Extraction (Generate Structured JSON) (OpenAI n8n node):
Function: Utilizes GPT-4o-mini to analyze the cleaned invoice text and extract specific data points into a standardized JSON structure.
Key Configuration: Uses a detailed system prompt for schema enforcement (e.g., extracting total, invoicedate, bankinfo), ensuring the output is always valid JSON.
Parse AI Output to JSON (Code n8n node):
Function: Safely converts the AI's textual JSON output string back into a usable data object within the n8n workflow.
Append to Google Sheets (Google Sheets n8n node):
Function: The final action, which writes the structured data extracted by the AI into the designated row in the Google Sheet ledger.
Key Configuration: Dynamically sets the Sheet Name based on the discovered monthly folder and maps all extracted invoice fields (like total, tax, dates, and PDF link) to specific column headers. This completes the essential step of this automated n8n workflow.

Related n8n Workflows

Free

Nodes: 7 Nodes
Updated: December 26 2025
View all
Created by
Supira Inc.
Supira Inc.

Featured*