Automated Invoice Processing with Gmail, OCR, Slack & Xero - n8n Workflow

Streamline Accounts Payable using this robust n8n workflow template. Automatically extract data from emailed invoices (PDF/image), validate parameters, gain required approvals via Slack, and seamlessly sync finalized data to Google Sheets and Xero. Implement this advanced n8n workflow today.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Finance teams and AP specialists looking to eliminate manual invoice data entry.

  • Operations managers seeking to enforce structured approval processes.

  • Users who need high-value, production-ready n8n templates integrating mail, OCR, and accounting systems.

  • Businesses relying on Gmail as the intake point for vendor invoices.

Overview

Manual invoice processing is a major bottleneck for finance teams, leading to delayed payments, data errors, and poor audit trails. This comprehensive n8n workflow tackles this challenge head-on by creating a fully automated Accounts Payable intake and approval system. Starting with the powerful Gmail n8n trigger, the system automatically detects PDF or image invoices, uses external OCR for data extraction, validates the resulting data against preset business rules (like amount limits), and then routes the data for human review via a Slack approval request. Only approved invoices proceed to be logged in Google Sheets and posted as a draft in Xero. This single, efficient n8n workflow significantly reduces processing time and provides clear visibility and audit capability.

How it Works

This complex n8n workflow operates in three major phases:


  1. Extraction and Parsing (Gmail & OCR): The n8n trigger watches for new Gmail messages containing PDF or image attachments. A JavaScript n8n node processes the binary data, base64-encodes it, and sends it to the OCR.space API via an HTTP Request n8n node for text extraction. A second Code n8n node parses this raw text using complex regex, extracting structured fields like vendor name, invoice number, amount, and dates. It also runs initial qualification checks (e.g., ensuring mandatory fields exist and the amount is under a specified threshold).

  2. Qualification and Approval Routing (If & Slack): The Check Qualification If n8n node routes the flow. If the invoice fails validation (e.g., missing data or exceeding $10,000), the flow proceeds down the rejection path, sending an alert via Slack, and applying a 'Rejected' label in Gmail. If qualified, the data is logged as 'Pending' in Google Sheets. It then utilizes the Slack Approval Request n8n node, which pauses the n8n workflow execution until a user explicitly approves or rejects the invoice via an interactive message.

  3. Final Sync and Notification (Xero & Sheets): The Was Approved? If n8n node determines the final action. If approved, the n8n workflow fetches the relevant contact details from Xero and creates a new DRAFT invoice via an HTTP Request n8n node. It subsequently updates the invoice status to 'Approved' in Google Sheets, applies a 'Processed' label in Gmail, and sends a success notification via Slack. If rejected at the Slack stage, it follows the rejection procedures, updating Google Sheets status to 'Rejected' and notifying the team.

Installation Guide

To deploy this expert n8n workflow template, follow these steps:


  1. Import: Copy the provided JSON data and import it into your n8n instance via the 'Workflows' section.

  2. Gmail Trigger Setup: Configure the Gmail Trigger n8n node with your Gmail OAuth2 credentials. Ensure the filter has:attachment filename:pdf is correctly set.

  3. OCR Credential: Set up an HTTP Request Credential named ocrspaceApi containing your OCR.space API key. This is used by the Extract Text n8n node.

  4. Google Sheets Setup: Configure Google Sheets OAuth2 credentials and update the spreadsheet ID placeholders in both Append or update row in sheet and Update Approved Status n8n nodes.

  5. Slack Setup: Configure Slack OAuth2 credentials for sending and receiving interactive approval messages. Ensure the correct Channel IDs are used across all Slack n8n nodes (Slack Approval Request, Slack Rejection message, Success message, Rejection message).

  6. Xero Setup: Configure Xero OAuth2 credentials for the Get many contacts n8n node and the Create invoice HTTP Request n8n node. Note that the Xero organization ID placeholder must be updated.

  7. Activate: Save and activate the n8n workflow. It is now ready to be triggered by incoming emails.

Node Details

Gmail Trigger (n8n trigger): The starting point of the n8n workflow. Polls Gmail for new emails containing PDF attachments.
Code in JavaScript: Prepares the attachment for OCR, base64-encoding the file and constructing the dataUrl. It also ensures binary data validation.
Extract Text (HTTP Request n8n node): Sends the base64-encoded invoice image/PDF to OCR.space for highly accurate text extraction.
Parse Invoice Data (Code in JavaScript): The core logic engine. It uses JavaScript regex patterns to transform raw OCR text into structured data fields (amount, vendor, date) and performs crucial internal validation checks.
Check Qualification (If n8n node): Routes the n8n workflow based on the success of the data parsing and initial validation rules.
Append or update row in sheet (Google Sheets n8n node): Logs the extracted invoice data into a Google Sheet for tracking, using the Invoice Number as the matching column.
Slack Approval Request (Slack n8n node): Sends an interactive message, pausing the n8n workflow execution until human approval is received. This is a critical flow control mechanism in the n8n template.
Was Approved? (If n8n node): Branches the flow based on the human response received from the Slack approval step.
Create invoice (HTTP Request n8n node): Posts the approved invoice data to the Xero API, utilizing parameters mapped from earlier n8n nodes, finalizing the Accounts Payable process.
Add Processed/Rejected label (Gmail n8n node): A utility n8n node that applies specific labels in Gmail to categorize the source email, ensuring a clean inbox and robust audit trail.

Related n8n Workflows

Free

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

Automation Builder with extensive experience helping businesses streamline processes and generate revenue.

Featured*