自动化PDF发票处理与审批流程,使用OpenAI和Google表格
这是一个Finance、AI领域的自动化工作流,包含 17 个节点。主要使用 If、Gmail、FormTrigger、GoogleDrive、GmailTrigger 等节点,结合人工智能技术实现智能自动化。 自动化PDF发票处理与审批流程,使用OpenAI和Google表格
- •Google 账号和 Gmail API 凭证
- •Google Drive API 凭证
- •Google Sheets API 凭证
- •OpenAI API Key
使用的节点 (17 个)
{
"meta": {
"instanceId": "d1786ab0d745a7498abf13a9c2cdabb1374c006e889b79eef64ce0386b8f8a41",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "32dec238-615e-461d-ac9b-e09bdcb2a73f",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
560,
200
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "MGwGMKEkdcjzlYCw",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "4cb973bc-385f-42db-b79e-942c75d97a84",
"name": "多表:您可以连接多个表以实现有组织的数据结构",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
780,
200
],
"parameters": {
"jsonSchemaExample": "{\n \"invoice_number\": \"\",\n \"invoice_date\": \"\",\n \"due_date\": \"\",\n \"vendor_name\": \"\",\n \"total_amount\": \"\",\n \"currency\": \"\",\n \"items\": [\n {\n \"description\": \"\",\n \"amount\": \"\"\n }\n ],\n \"tax\": \"\",\n \"category\": \"\"\n}"
},
"typeVersion": 1.2
},
{
"id": "b7ed6cf6-e965-43e0-abab-919ab598e62a",
"name": "发票文件夹监视器",
"type": "n8n-nodes-base.googleDriveTrigger",
"position": [
-100,
-220
],
"parameters": {
"event": "fileCreated",
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"triggerOn": "specificFolder",
"folderToWatch": {
"__rl": true,
"mode": "id",
"value": "1KJ4fvXcKVMGJunsKvPYf8PkX5K9SVwFk"
}
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "SEUhrgz30NMJS3cH",
"name": "Google Drive account"
}
},
"typeVersion": 1
},
{
"id": "d2a0d543-1ee3-4852-9751-69aae3b9864a",
"name": "下载发票 PDF",
"type": "n8n-nodes-base.googleDrive",
"position": [
100,
-220
],
"parameters": {
"fileId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.id }}"
},
"options": {},
"operation": "download"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "SEUhrgz30NMJS3cH",
"name": "Google Drive account"
}
},
"typeVersion": 3
},
{
"id": "80345f83-02fa-47ab-86f0-1e01bd3429e7",
"name": "发票解析 AI 代理",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
580,
0
],
"parameters": {
"text": "=You are an intelligent invoice parser. I will give you raw text extracted from a PDF invoice. \n\n========================\nSTART OF RAW INVOICE TEXT\n\n{{ $json.text }}\n\nEND OF RAW INVOICE TEXT\n========================\n\nYour job is to:\n\n1. Extract key information from the invoice such as:\n - invoice_number\n - invoice_date\n - due_date (if available)\n - vendor_name\n - total_amount\n - currency (e.g., USD, IDR, etc.)\n - items (as a list of item descriptions and their amounts)\n - tax (if available)\n\n2. Detect the invoice **category**, such as:\n - Utilities\n - Office Supplies\n - Travel\n - Software\n - Food & Beverage\n - Others (if unknown)\n\n3. Return the result in this exact JSON format:\n\n```json\n{\n \"invoice_number\": \"\",\n \"invoice_date\": \"\",\n \"due_date\": \"\",\n \"vendor_name\": \"\",\n \"total_amount\": \"\",\n \"currency\": \"\",\n \"items\": [\n {\n \"description\": \"\",\n \"amount\": \"\"\n }\n ],\n \"tax\": \"\",\n \"category\": \"\"\n}\n",
"options": {},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 1.9
},
{
"id": "57649f6a-2d4d-4072-92bd-ffea26fdd4dd",
"name": "插入发票数据",
"type": "n8n-nodes-base.googleSheets",
"position": [
1460,
0
],
"parameters": {
"columns": {
"value": {
"Tax": "={{ $('Invoice Parser AI Agent').item.json.output.tax }}",
"Items": "={{ $('Invoice Parser AI Agent').item.json.output.items }}",
"Approved": "={{ $json.data['Approve Invoice?'] }}",
"Category": "={{ $('Invoice Parser AI Agent').item.json.output.category }}",
"Currency": "={{ $('Invoice Parser AI Agent').item.json.output.currency }}",
"Due Date": "={{ $('Invoice Parser AI Agent').item.json.output.due_date }}",
"Reviewed By": "={{ $json.data['Reviewed By'] }}",
"Vendor Name": "={{ $('Invoice Parser AI Agent').item.json.output.vendor_name }}",
"Invoice Date": "={{ $('Invoice Parser AI Agent').item.json.output.invoice_date }}",
"Total Amount": "={{ $('Invoice Parser AI Agent').item.json.output.total_amount }}",
"Approval Notes": "={{ $json.data['Approval Notes'] }}",
"Invoice Number": "={{ $('Invoice Parser AI Agent').item.json.output.invoice_number }}"
},
"schema": [
{
"id": "Invoice Number",
"type": "string",
"display": true,
"required": false,
"displayName": "Invoice Number",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Invoice Date",
"type": "string",
"display": true,
"required": false,
"displayName": "Invoice Date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Due Date",
"type": "string",
"display": true,
"required": false,
"displayName": "Due Date",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Vendor Name",
"type": "string",
"display": true,
"required": false,
"displayName": "Vendor Name",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Total Amount",
"type": "string",
"display": true,
"required": false,
"displayName": "Total Amount",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Currency",
"type": "string",
"display": true,
"required": false,
"displayName": "Currency",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Items",
"type": "string",
"display": true,
"required": false,
"displayName": "Items",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Tax",
"type": "string",
"display": true,
"required": false,
"displayName": "Tax",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Category",
"type": "string",
"display": true,
"required": false,
"displayName": "Category",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Approved",
"type": "string",
"display": true,
"required": false,
"displayName": "Approved",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Approval Notes",
"type": "string",
"display": true,
"required": false,
"displayName": "Approval Notes",
"defaultMatch": false,
"canBeUsedToMatch": true
},
{
"id": "Reviewed By",
"type": "string",
"display": true,
"required": false,
"displayName": "Reviewed By",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [],
"attemptToConvertTypes": false,
"convertFieldsToString": false
},
"options": {},
"operation": "append",
"sheetName": {
"__rl": true,
"mode": "list",
"value": "gid=0",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ueJfN5dFTXY3_AdvnYUL5_RjV9YwSFvbxwA_ivtqnJk/edit#gid=0",
"cachedResultName": "Invoices"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1ueJfN5dFTXY3_AdvnYUL5_RjV9YwSFvbxwA_ivtqnJk",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1ueJfN5dFTXY3_AdvnYUL5_RjV9YwSFvbxwA_ivtqnJk/edit?usp=drivesdk",
"cachedResultName": "Copy of PDF Invoice Parser - n8n template"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "ypmzFxQFfAacuVVC",
"name": "Google Sheets account"
}
},
"typeVersion": 4.5
},
{
"id": "2993f865-d46c-489b-ab34-3c62b2c3cb1f",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-460,
-220
],
"parameters": {
"color": 4,
"width": 280,
"height": 500,
"content": "## 需要设置"
},
"typeVersion": 1
},
{
"id": "691f4972-8d18-49fd-b8cd-0c6b2464b078",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-120,
420
],
"parameters": {
"color": 5,
"width": 700,
"height": 560,
"content": "## 🧾 使用OpenAI和Google Sheets的自动化PDF发票处理与审批流程"
},
"typeVersion": 1
},
{
"id": "2463666d-8c40-4821-b907-9741e62ce1e7",
"name": "便签4",
"type": "n8n-nodes-base.stickyNote",
"position": [
620,
420
],
"parameters": {
"color": 5,
"width": 620,
"height": 620,
"content": "## 📋 工作流流程概览"
},
"typeVersion": 1
},
{
"id": "8483b8ef-83d7-4b3f-ad54-b9ec23efc911",
"name": "发送发票以供审批",
"type": "n8n-nodes-base.gmail",
"position": [
920,
0
],
"webhookId": "a23938a4-fc6c-4445-8dee-17e501e92e06",
"parameters": {
"sendTo": "replace_with_approver_email@yopmail.com",
"message": "=A new invoice has been submitted and requires your review and approval:",
"options": {},
"subject": "=[Action Required] Invoice Approval Request – {{ $json.output.vendor_name }}",
"operation": "sendAndWait",
"formFields": {
"values": [
{
"fieldType": "dropdown",
"fieldLabel": "Approve Invoice?",
"fieldOptions": {
"values": [
{
"option": "Yes"
},
{
"option": "No"
}
]
},
"requiredField": true
},
{
"fieldLabel": "Reviewed By",
"requiredField": true
},
{
"fieldType": "textarea",
"fieldLabel": "Approval Notes"
}
]
},
"responseType": "customForm"
},
"credentials": {
"gmailOAuth2": {
"id": "sWl7FFMkEUYBj0zM",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "0fece28b-13c8-4b0d-9c1b-84047a3503f6",
"name": "监控电子邮件附件",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
100,
0
],
"parameters": {
"simple": false,
"filters": {},
"options": {
"downloadAttachments": true,
"dataPropertyAttachmentsPrefixName": "attachment_"
},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"credentials": {
"gmailOAuth2": {
"id": "sWl7FFMkEUYBj0zM",
"name": "Gmail account"
}
},
"typeVersion": 1.2
},
{
"id": "d210d1c5-865f-494e-a69c-d25ac462869b",
"name": "上传发票(PDF)表单",
"type": "n8n-nodes-base.formTrigger",
"position": [
100,
200
],
"webhookId": "e033bea9-70e8-41e2-aea4-1b95714ea257",
"parameters": {
"options": {},
"formTitle": "Upload Invoice (PDF)",
"formFields": {
"values": [
{
"fieldType": "file",
"fieldLabel": "Upload",
"multipleFiles": false,
"requiredField": true,
"acceptFileTypes": ".pdf"
}
]
},
"formDescription": "Upload your invoice PDF using this form."
},
"typeVersion": 2.2
},
{
"id": "4703ddb5-1e07-43b9-a465-c9aced0ac9d8",
"name": "从Drive PDF提取文本",
"type": "n8n-nodes-base.extractFromFile",
"position": [
300,
-220
],
"parameters": {
"options": {},
"operation": "pdf"
},
"typeVersion": 1
},
{
"id": "7ca78f71-8c1e-42e2-8686-08f2a9bfc009",
"name": "从电子邮件PDF提取文本",
"type": "n8n-nodes-base.extractFromFile",
"position": [
300,
0
],
"parameters": {
"options": {},
"operation": "pdf",
"binaryPropertyName": "attachment_0"
},
"typeVersion": 1
},
{
"id": "0b4aff7d-8c92-4964-a38c-996b546ed23a",
"name": "从表单PDF提取文本",
"type": "n8n-nodes-base.extractFromFile",
"position": [
300,
200
],
"parameters": {
"options": {},
"operation": "pdf",
"binaryPropertyName": "Upload"
},
"typeVersion": 1
},
{
"id": "eef8e5e5-2b01-4ddd-8ea2-312fb41356de",
"name": "检查审批决定",
"type": "n8n-nodes-base.if",
"position": [
1180,
0
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "451bfdfc-f645-4e3c-91cc-895558f45b11",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.data['Approve Invoice?'] }}",
"rightValue": "Yes"
}
]
}
},
"typeVersion": 2.2
},
{
"id": "ac5dd79d-9d32-44f9-8a9b-2cc45757110b",
"name": "发送拒绝提醒",
"type": "n8n-nodes-base.gmail",
"position": [
1320,
260
],
"webhookId": "1c33c42a-0d8e-466f-a424-faba306c56af",
"parameters": {
"sendTo": "finance_team@yopmail.com",
"message": "=Hi Finance Team,\n\nAn invoice from {{ $('Invoice Parser AI Agent').item.json.output.vendor_name }} has been disapproved during the approval process.\n\nReviewed By: {{ $('Send Invoice for Approval').item.json.data['Reviewed By'] }}\nApproval Notes: {{ $('Send Invoice for Approval').item.json.data['Approval Notes'] }}\n\nPlease review and follow up as needed.\n\nThank you,\nAutomated Invoice System\n\n",
"options": {
"appendAttribution": false
},
"subject": "=[Alert] Invoice Disapproved – {{ $('Invoice Parser AI Agent').item.json.output.vendor_name }}",
"emailType": "text"
},
"credentials": {
"gmailOAuth2": {
"id": "sWl7FFMkEUYBj0zM",
"name": "Gmail account"
}
},
"typeVersion": 2.1
}
],
"pinData": {
"Invoice Parser AI Agent": [
{
"output": {
"tax": "8.50",
"items": [
{
"amount": "85.00",
"description": "Web Design - This is a sample description..."
}
],
"category": "Others",
"currency": "USD",
"due_date": "January 31, 2016",
"vendor_name": "DEMO - Sliced Invoices",
"invoice_date": "January 25, 2016",
"total_amount": "93.50",
"invoice_number": "INV-3337"
}
}
],
"Send Invoice for Approval": [
{
"data": {
"Reviewed By": "jack",
"Approval Notes": "notes approval",
"Approve Invoice?": "Yes"
}
}
]
},
"connections": {
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Invoice Parser AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Download Invoice PDF": {
"main": [
[
{
"node": "Extract Text from Drive PDF",
"type": "main",
"index": 0
}
]
]
},
"Send Rejection Alert": {
"main": [
[
{
"node": "Insert Invoice Data",
"type": "main",
"index": 0
}
]
]
},
"Invoice Folder Monitor": {
"main": [
[
{
"node": "Download Invoice PDF",
"type": "main",
"index": 0
}
]
]
},
"Check Approval Decision": {
"main": [
[
{
"node": "Insert Invoice Data",
"type": "main",
"index": 0
}
],
[
{
"node": "Send Rejection Alert",
"type": "main",
"index": 0
}
]
]
},
"Invoice Parser AI Agent": {
"main": [
[
{
"node": "Send Invoice for Approval",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "Invoice Parser AI Agent",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Monitor Email Attachments": {
"main": [
[
{
"node": "Extract Text from Email PDF",
"type": "main",
"index": 0
}
]
]
},
"Send Invoice for Approval": {
"main": [
[
{
"node": "Check Approval Decision",
"type": "main",
"index": 0
}
]
]
},
"Upload Invoice (PDF) Form": {
"main": [
[
{
"node": "Extract Text from Form PDF",
"type": "main",
"index": 0
}
]
]
},
"Extract Text from Form PDF": {
"main": [
[
{
"node": "Invoice Parser AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Extract Text from Drive PDF": {
"main": [
[
{
"node": "Invoice Parser AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Extract Text from Email PDF": {
"main": [
[
{
"node": "Invoice Parser AI Agent",
"type": "main",
"index": 0
}
]
]
}
}
}如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个高级难度的工作流,适用于Finance、AI等场景。适合高级用户,包含 16+ 个节点的复杂工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
Billy Christi
@billyI'm a professional software engineer and n8n expert with a passion for building scalable, no-code and low-code automation workflows. I specialize in creating seamless integrations between APIs, CRMs, and everyday tools to help businesses save time, reduce manual work, and operate smarter. Whether it's automating marketing pipelines, backend systems, or approval processes, I turn complex logic into simple, powerful workflows with n8n.
分享此工作流