Extract and validate invoice PDFs from email with OpenAI, Sheets and Xero
Ready for 3.0What this workflow does
This AI workflow has 25 nodes and runs when a new email arrives over IMAP (plus 1 other trigger). Along the way it connects Google Sheets and OpenAI Chat Model. It also calls api.xero.com over HTTP.
How it runs
Trigger: When a new email arrives over IMAP (plus 1 other trigger).
- Config (Edit Fields (Set)): sets 7 fields: workflow_label, model, total_tolerance…
- One item per PDF (Code): runs custom JavaScript code
- Sample run? (If): checks a condition and branches into true / false
- Has a text layer? (Code): runs custom JavaScript code
- Extract PDF text (Extract from File): extracts data from a file (pdf)
- Scanned? (If): checks a condition and branches into true / false
- Describe failure (Code): runs custom JavaScript code
- Scan to review (Code): runs custom JavaScript code
- Extract fields (AI) (Basic LLM Chain): sends a prompt to an LLM, with model: OpenAI model; output parser: Invoice schema
- Failure alert (Slack) (HTTP Request): calls an HTTP API (POST)
…plus 11 more steps. See the full node list below.
Services it uses
Other OpenAI + Google Sheets templates (2,011) · Other Xero + OpenAI templates (10) · Other Xero + Google Sheets templates (6)
HTTP calls to: api.xero.com
Before you upgrade to n8n 3.0
Nothing in this workflow is removed in n8n 3.0, so it should import and run after the upgrade.
- Code node: the task timeout drops from 300s to 60s. Test with a realistic data volume.
Nodes used (12)
- Email Trigger (IMAP)
n8n-nodes-base.emailReadImap - Manual Trigger
n8n-nodes-base.manualTrigger - Edit Fields (Set)
n8n-nodes-base.set - Code
n8n-nodes-base.code - If
n8n-nodes-base.if - Extract from File
n8n-nodes-base.extractFromFile - Google Sheets
n8n-nodes-base.googleSheets - Switch
n8n-nodes-base.switch - HTTP Request
n8n-nodes-base.httpRequest - Basic LLM Chain
@n8n/n8n-nodes-langchain.chainLlm - OpenAI Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenAi - Structured Output Parser
@n8n/n8n-nodes-langchain.outputParserStructured
From the author
Quick overview This workflow monitors an IMAP inbox for invoice PDF attachments, extracts structured invoice fields with OpenAI, validates totals and dates, logs results to Google Sheets, and optionally creates draft bills in Xero while sending Slack alerts…