{"name": "Invoice Extraction & Reconciliation Pipeline", "nodes": [{"id": "inv3-0000-4a5b-8c9d-000000000001", "name": "Sticky Note", "type": "n8n-nodes-base.stickyNote", "typeVersion": 1, "position": [160, -80], "parameters": {"color": 4, "content": "## Invoice Extraction & Reconciliation Pipeline\n\n**Setup (10 min):**\n1. Create credentials: Gmail OAuth2, OpenAI, Google Sheets OAuth2, Slack OAuth2; select them in every node.\n2. In the Google Sheets nodes, pick your spreadsheet and sheet (header row: date, vendor, amount, invoice_number, status).\n3. In *Gmail: Approval Request*, set the recipient to your finance team's email.\n4. In *IF: Amount > 1000*, set your approval threshold.\n5. Activate, then send yourself a test invoice email (subject contains 'invoice', with attachment).\n\n**Flow:** Gmail Trigger -> download attachment -> OpenAI extracts vendor/amount/date/invoice number -> Set normalizes -> Sheets appends row (status=pending) -> IF amount > threshold -> approval email -> Wait (form) -> IF -> Sheets updates status (reconciled / rejected / auto-reconciled) -> Slack notify.\n\n**Note:** if invoices arrive as PDFs, add an 'Extract from File' node before *OpenAI: Extract Invoice Data* so the AI reads the PDF text.", "height": 420, "width": 480}}, {"id": "inv3-0001-4a5b-8c9d-111111111111", "name": "Gmail Trigger: Invoice Email", "type": "n8n-nodes-base.gmailTrigger", "typeVersion": 1.2, "position": [240, 300], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"pollTimes": {"item": [{"mode": "everyMinute"}]}, "filters": {"q": "subject:invoice has:attachment"}}}, {"id": "inv3-0002-4a5b-8c9d-222222222222", "name": "Gmail: Download Attachment", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [480, 300], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"resource": "message", "operation": "getAttachment", "messageId": "={{ $('Gmail Trigger: Invoice Email').item.json.id }}", "attachmentId": "={{ $json.payload.parts[0].body.attachmentId }}", "options": {}}}, {"id": "inv3-0003-4a5b-8c9d-333333333333", "name": "OpenAI: Extract Invoice Data", "type": "n8n-nodes-base.openAi", "typeVersion": 1, "position": [720, 300], "credentials": {"openAiApi": {"id": "", "name": "OpenAI API"}}, "parameters": {"resource": "text", "operation": "message", "model": "gpt-4o-mini", "messages": {"message": [{"role": "user", "content": "=Extract the invoice details from the text below. Reply with ONLY valid JSON, no markdown, no explanation.\n\n{\"vendor\": \"vendor name\", \"amount\": 1234.56, \"date\": \"YYYY-MM-DD\", \"invoice_number\": \"invoice number or empty string\"}\n\nInvoice text:\n{{ $json.text }}"}]}, "options": {}}}, {"id": "inv3-0004-4a5b-8c9d-444444444444", "name": "Set: Normalize Fields", "type": "n8n-nodes-base.set", "typeVersion": 3.4, "position": [960, 300], "parameters": {"assignments": {"assignments": [{"id": "b1", "name": "vendor", "value": "={{ $json.message.content.vendor }}", "type": "string"}, {"id": "b2", "name": "amount", "value": "={{ Number($json.message.content.amount) }}", "type": "number"}, {"id": "b3", "name": "date", "value": "={{ $json.message.content.date }}", "type": "string"}, {"id": "b4", "name": "invoice_number", "value": "={{ $json.message.content.invoice_number }}", "type": "string"}, {"id": "b5", "name": "status", "value": "pending", "type": "string"}]}, "options": {}}}, {"id": "inv3-0005-4a5b-8c9d-555555555555", "name": "Google Sheets: Log Invoice", "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.2, "position": [1200, 300], "credentials": {"googleSheetsOAuth2Api": {"id": "", "name": "Google Sheets"}}, "parameters": {"resource": "sheetWithinDocument", "operation": "append", "documentId": {"__rl": true, "mode": "url", "value": "", "cachedResultUrl": ""}, "sheetName": {"__rl": true, "mode": "list", "value": "Sheet1", "cachedResultName": "Sheet1"}, "columns": {"mappingMode": "defineBelow", "value": {"date": "={{ $json.date }}", "vendor": "={{ $json.vendor }}", "amount": "={{ $json.amount }}", "invoice_number": "={{ $json.invoice_number }}", "status": "={{ $json.status }}"}, "matchingColumns": [], "schema": [{"id": "date", "displayName": "date", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}, {"id": "vendor", "displayName": "vendor", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}, {"id": "amount", "displayName": "amount", "required": false, "defaultMatch": false, "display": true, "type": "number", "canBeUsedToMatch": true}, {"id": "invoice_number", "displayName": "invoice_number", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}, {"id": "status", "displayName": "status", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}]}, "options": {}}}, {"id": "inv3-0006-4a5b-8c9d-666666666666", "name": "IF: Amount > 1000", "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [1440, 300], "parameters": {"conditions": {"options": {"caseSensitive": true, "leftValue": "", "typeValidation": "strict"}, "conditions": [{"id": "d1", "leftValue": "={{ $json.amount }}", "rightValue": 1000, "operator": {"type": "number", "operation": "larger", "name": "filter.operator.number.larger"}}], "combinator": "and"}, "options": {}}}, {"id": "inv3-0007-4a5b-8c9d-777777777777", "name": "Gmail: Approval Request", "type": "n8n-nodes-base.gmail", "typeVersion": 2.1, "position": [1680, 300], "credentials": {"gmailOAuth2": {"id": "", "name": "Gmail"}}, "parameters": {"resource": "message", "operation": "send", "subject": "=Invoice approval needed: {{ $('Set: Normalize Fields').item.json.invoice_number }}", "email": "finance@example.com", "message": "=Hi,\n\nAn invoice needs approval:\n\nVendor: {{ $('Set: Normalize Fields').item.json.vendor }}\nAmount: {{ $('Set: Normalize Fields').item.json.amount }}\nDate: {{ $('Set: Normalize Fields').item.json.date }}\nInvoice number: {{ $('Set: Normalize Fields').item.json.invoice_number }}\n\nApprove or reject it here:\n{{ $execution.resumeUrl }}", "options": {}}}, {"id": "inv3-0008-4a5b-8c9d-888888888888", "name": "Wait: Finance Approval", "type": "n8n-nodes-base.wait", "typeVersion": 1.1, "position": [1920, 300], "parameters": {"resume": "onFormSubmission", "options": {"formTitle": "Approve this invoice?", "formDescription": "Review the invoice details from the email, then approve or reject it.", "formFields": {"values": [{"fieldLabel": "Decision", "fieldType": "dropdown", "requiredField": true, "fieldOptions": {"values": [{"option": "Approve"}, {"option": "Reject"}]}}]}, "responseType": "allEntries"}}}, {"id": "inv3-0009-4a5b-8c9d-999999999999", "name": "IF: Finance Approved?", "type": "n8n-nodes-base.if", "typeVersion": 2.2, "position": [2160, 300], "parameters": {"conditions": {"options": {"caseSensitive": true, "leftValue": "", "typeValidation": "strict"}, "conditions": [{"id": "e1", "leftValue": "={{ $json.Decision }}", "rightValue": "Approve", "operator": {"type": "string", "operation": "equals", "name": "filter.operator.string.equals"}}], "combinator": "and"}, "options": {}}}, {"id": "inv3-0010-4a5b-8c9d-aaaaaaaaaaaaaaaa", "name": "Google Sheets: Mark Reconciled", "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.2, "position": [2400, 300], "credentials": {"googleSheetsOAuth2Api": {"id": "", "name": "Google Sheets"}}, "parameters": {"resource": "sheetWithinDocument", "operation": "update", "documentId": {"__rl": true, "mode": "url", "value": "", "cachedResultUrl": ""}, "sheetName": {"__rl": true, "mode": "list", "value": "Sheet1", "cachedResultName": "Sheet1"}, "columns": {"mappingMode": "defineBelow", "value": {"status": "reconciled"}, "matchingColumns": ["invoice_number"], "schema": [{"id": "invoice_number", "displayName": "invoice_number", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}, {"id": "status", "displayName": "status", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}]}, "options": {}}}, {"id": "inv3-0011-4a5b-8c9d-bbbbbbbbbbbb", "name": "Google Sheets: Mark Rejected", "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.2, "position": [2400, 500], "credentials": {"googleSheetsOAuth2Api": {"id": "", "name": "Google Sheets"}}, "parameters": {"resource": "sheetWithinDocument", "operation": "update", "documentId": {"__rl": true, "mode": "url", "value": "", "cachedResultUrl": ""}, "sheetName": {"__rl": true, "mode": "list", "value": "Sheet1", "cachedResultName": "Sheet1"}, "columns": {"mappingMode": "defineBelow", "value": {"status": "rejected"}, "matchingColumns": ["invoice_number"], "schema": [{"id": "invoice_number", "displayName": "invoice_number", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}, {"id": "status", "displayName": "status", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}]}, "options": {}}}, {"id": "inv3-0012-4a5b-8c9d-cccccccccccc", "name": "Google Sheets: Mark Auto-Reconciled", "type": "n8n-nodes-base.googleSheets", "typeVersion": 4.2, "position": [1680, 500], "credentials": {"googleSheetsOAuth2Api": {"id": "", "name": "Google Sheets"}}, "parameters": {"resource": "sheetWithinDocument", "operation": "update", "documentId": {"__rl": true, "mode": "url", "value": "", "cachedResultUrl": ""}, "sheetName": {"__rl": true, "mode": "list", "value": "Sheet1", "cachedResultName": "Sheet1"}, "columns": {"mappingMode": "defineBelow", "value": {"status": "auto-reconciled"}, "matchingColumns": ["invoice_number"], "schema": [{"id": "invoice_number", "displayName": "invoice_number", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}, {"id": "status", "displayName": "status", "required": false, "defaultMatch": false, "display": true, "type": "string", "canBeUsedToMatch": true}]}, "options": {}}}, {"id": "inv3-0013-4a5b-8c9d-dddddddddddd", "name": "Slack: Notify", "type": "n8n-nodes-base.slack", "typeVersion": 2.3, "position": [1920, 500], "credentials": {"slackOAuth2Api": {"id": "", "name": "Slack"}}, "parameters": {"channel": "#finance", "text": "=Invoice auto-reconciled (under threshold): {{ $('Set: Normalize Fields').item.json.vendor }} - {{ $('Set: Normalize Fields').item.json.amount }}", "otherOptions": {}}}], "connections": {"Gmail Trigger: Invoice Email": {"main": [[{"node": "Gmail: Download Attachment", "type": "main", "index": 0}]]}, "Gmail: Download Attachment": {"main": [[{"node": "OpenAI: Extract Invoice Data", "type": "main", "index": 0}]]}, "OpenAI: Extract Invoice Data": {"main": [[{"node": "Set: Normalize Fields", "type": "main", "index": 0}]]}, "Set: Normalize Fields": {"main": [[{"node": "Google Sheets: Log Invoice", "type": "main", "index": 0}]]}, "Google Sheets: Log Invoice": {"main": [[{"node": "IF: Amount > 1000", "type": "main", "index": 0}]]}, "IF: Amount > 1000": {"main": [[{"node": "Gmail: Approval Request", "type": "main", "index": 0}], [{"node": "Google Sheets: Mark Auto-Reconciled", "type": "main", "index": 0}]]}, "Gmail: Approval Request": {"main": [[{"node": "Wait: Finance Approval", "type": "main", "index": 0}]]}, "Wait: Finance Approval": {"main": [[{"node": "IF: Finance Approved?", "type": "main", "index": 0}]]}, "IF: Finance Approved?": {"main": [[{"node": "Google Sheets: Mark Reconciled", "type": "main", "index": 0}], [{"node": "Google Sheets: Mark Rejected", "type": "main", "index": 0}]]}, "Google Sheets: Mark Auto-Reconciled": {"main": [[{"node": "Slack: Notify", "type": "main", "index": 0}]]}}, "active": false, "settings": {"executionOrder": "v1"}, "versionId": "cortexflow-invoice-extraction-reconciliation-v1", "meta": {"templateCredsSetupCompleted": false, "instanceId": ""}, "pinData": {}, "tags": [{"name": "cortexflow-template"}]}