Quick Overview
This workflow watches Gmail for emails with invoice attachments, uses EmpirioLabs AI to OCR each PDF or image and extract key invoice fields, then logs validated results to Google Sheets and emails a reviewer when an invoice is missing required data or totals do not match.
How it works
- Triggers every 5 minutes by polling Gmail for messages matching a search query (default: emails with attachments and “invoice” in the subject) and downloads attachments.
- Splits each email into individual items per PDF or supported image attachment, skipping small images (like logos) and oversized files.
- Uses EmpirioLabs AI Document Read (OCR) to convert each attachment into text, and skips extraction when no text is found.
- Uses an EmpirioLabs AI chat model to extract invoice fields (vendor, invoice number, dates, currency, subtotal, tax, total) as JSON, then validates required fields and checks that subtotal plus tax matches total.
- Reads the existing invoice log from Google Sheets and compares by a generated invoice key to skip duplicates or flag invoices whose totals changed.
- Appends or updates the invoice row in Google Sheets, and emails a reviewer via Gmail when the invoice status is marked “Needs review.”
Setup
- Install the EmpirioLabs AI community node (n8n-nodes-empiriolabs v0.3.0+) and add an EmpirioLabs AI API key credential.
- Add Gmail and Google Sheets credentials with access to the mailbox and the target spreadsheet.
- Create a Google Sheet with the expected columns (including “Invoice key” as the matching column) and set the spreadsheet URL, sheet name, and reviewer email in the workflow settings.
- Update the Gmail search query and select the EmpirioLabs AI document model (OCR) and chat model used for extraction.