从Gmail标签使用GPT-4O + QuickBooks自动创建发票
高级
这是一个Invoice Processing, AI Summarization领域的自动化工作流,包含 23 个节点。主要使用 Code, Gmail, Quickbooks, Agent, ScheduleTrigger 等节点。 从Gmail标签使用GPT-4O + QuickBooks自动创建发票
前置要求
- •Google 账号和 Gmail API 凭证
- •OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "d6e2f2f655b1125bbcac14a4cac6d2e46c7a150e927f85fc96fdca1a6dc39e0e",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "5f0e5680-7bb4-4c96-b427-233f0fd35d9a",
"name": "将客户添加到 QBO",
"type": "n8n-nodes-base.quickbooks",
"onError": "continueRegularOutput",
"position": [
540,
500
],
"parameters": {
"operation": "create",
"displayName": "={{ $json.output.company_name ? $json.output.company_name : $json.output.client_full_name }}",
"additionalFields": {
"BillAddr": {
"details": {
"City": "={{ $json.output.city }}",
"Line1": "={{ $json.output.address_line_1 }}",
"PostalCode": "={{ $json.output.postal_code }}",
"CountrySubDivisionCode": "CA"
}
},
"GivenName": "={{ $json.output.client_first_name }}",
"FamilyName": "={{ $json.output.client_last_name }}",
"CompanyName": "={{ $json.output.company_name ? $json.output.company_name : \"\" }}",
"PrimaryPhone": "={{ $json.output.client_phone }}",
"PrimaryEmailAddr": "={{ $json.output.client_email }}"
}
},
"credentials": {
"quickBooksOAuth2Api": {
"id": "6ufAa1KkttZDj17m",
"name": "QuickBooks Online account"
}
},
"typeVersion": 1
},
{
"id": "8d3af3f2-77ab-4788-8a92-2efc7be5ca42",
"name": "获取带有\"需要发票\"标签的消息",
"type": "n8n-nodes-base.gmail",
"position": [
220,
20
],
"webhookId": "1cb550a2-0c63-45a3-baa5-c04cd8d03f68",
"parameters": {
"simple": false,
"filters": {
"labelIds": [
"Label_6581962793477761592"
]
},
"options": {},
"operation": "getAll",
"returnAll": true
},
"credentials": {
"gmailOAuth2": {
"id": "YVZiLPppXZw84rIU",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "c76c499b-fd1b-440e-be22-3737a223c02c",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
60,
720
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "XqsFFpRk48U68Fou",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "6ef8c67e-c5ba-4dc0-97e9-eebfc1a47db0",
"name": "结构化输出解析器",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
280,
720
],
"parameters": {
"schemaType": "manual",
"inputSchema": "{\n\t\"type\": \"object\",\n\t\"properties\": {\n\t\t\"client_first_name\": {\n\t\t\t\"type\": \"string\"\n\t\t},\n \"client_last_name\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"client_full_name\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"company_name\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"client_email\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"client_phone\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"address_line_1\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"city\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"province\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"postal_code\": {\n \t\t\t\"type\": \"string\"\n \t\t},\n \"invoiceAmount\": {\n \t\t\t\"type\": \"double\"\n \t\t},\n \"invoiceDescription\": {\n \t\t\t\"type\": \"text\"\n \t\t}\n\t}\n}"
},
"typeVersion": 1.2
},
{
"id": "8e74cb95-64fa-4969-88ef-782631a1dbe9",
"name": "查找现有客户",
"type": "n8n-nodes-base.quickbooks",
"position": [
800,
500
],
"parameters": {
"limit": 1,
"filters": {
"query": "=WHERE DisplayName = '{{ $('AI Agent: Extract Customer & Invoice Details').item.json.output.company_name ? $('AI Agent: Extract Customer & Invoice Details').item.json.output.company_name : $('AI Agent: Extract Customer & Invoice Details').item.json.output.client_full_name }}'"
},
"operation": "getAll"
},
"credentials": {
"quickBooksOAuth2Api": {
"id": "6ufAa1KkttZDj17m",
"name": "QuickBooks Online account"
}
},
"typeVersion": 1
},
{
"id": "4c7cb8d6-97d2-49a7-9307-9faeb04b2573",
"name": "创建新发票",
"type": "n8n-nodes-base.quickbooks",
"position": [
1060,
520
],
"parameters": {
"Line": [
{
"Amount": "={{ $('AI Agent: Extract Customer & Invoice Details').item.json.output.invoiceAmount }}",
"itemId": "13",
"DetailType": "SalesItemLineDetail",
"TaxCodeRef": "5",
"Description": "={{ $('AI Agent: Extract Customer & Invoice Details').item.json.output.invoiceDescription }}"
}
],
"resource": "invoice",
"operation": "create",
"CustomerRef": "={{ $json.Id ? $json.Id : $('Add Client to QBO').item.json.Id }}",
"additionalFields": {
"DueDate": "={{ $now }}"
}
},
"credentials": {
"quickBooksOAuth2Api": {
"id": "6ufAa1KkttZDj17m",
"name": "QuickBooks Online account"
}
},
"typeVersion": 1
},
{
"id": "1df01733-3f95-478f-bc2e-2eba2d3da4a9",
"name": "下载发票",
"type": "n8n-nodes-base.quickbooks",
"position": [
640,
940
],
"parameters": {
"download": true,
"fileName": "=Invoice - {{ $json.CustomerRef.name ? $json.CustomerRef.name : $json.TxnDate }}.pdf",
"resource": "invoice",
"invoiceId": "={{ $json.Id }}",
"binaryProperty": "invoice"
},
"credentials": {
"quickBooksOAuth2Api": {
"id": "6ufAa1KkttZDj17m",
"name": "QuickBooks Online account"
}
},
"typeVersion": 1
},
{
"id": "6ca60364-5d5b-45e0-9d73-63c34b20c47d",
"name": "撰写给客户的草稿回复",
"type": "n8n-nodes-base.gmail",
"position": [
920,
940
],
"webhookId": "433b7c52-32b5-4bac-8d88-9b0cc63da43b",
"parameters": {
"message": "=<p>Hello {{ $('AI Agent: Extract Customer & Invoice Details').item.json.output.client_first_name }},</p>\n<p>Please see attached for your invoice:</p>\n<p>Best,<br>An Efficient Person</p>",
"options": {
"threadId": "={{ $('Combine all Messages in a Thread').item.json.threadId }}",
"attachmentsUi": {
"attachmentsBinary": [
{
"property": "invoice"
}
]
}
},
"subject": "=",
"resource": "draft",
"emailType": "html"
},
"credentials": {
"gmailOAuth2": {
"id": "YVZiLPppXZw84rIU",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "f5c6f49d-5e21-48ae-bc4e-750cd4d5bd4a",
"name": "定时触发器",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
-40,
20
],
"parameters": {
"rule": {
"interval": [
{
"field": "hours"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "c01cc24c-99cd-4c16-80db-db71a6362859",
"name": "AI 代理:提取客户和发票详细信息",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
60,
500
],
"parameters": {
"options": {
"systemMessage": "You are a helpful assistant who needs to create an invoice based on the email(s) provided. Please extract the necessary details to create an invoice:\n- Customer name and/or company name (if provided) (Required)\n- The amount of the invoice before taxes (Required)\n- The description of the product/service being purchased\n- Billing Address\n- client phone number\n- client email address\n- "
},
"hasOutputParser": true
},
"typeVersion": 1.9
},
{
"id": "60aeb85f-b6ef-4c47-bb88-d2431a95f7f2",
"name": "移除\"需要发票\"标签",
"type": "n8n-nodes-base.gmail",
"position": [
1180,
940
],
"webhookId": "406d3985-d16c-421e-b6a8-5e36b5df7db8",
"parameters": {
"labelIds": [
"Label_6581962793477761592"
],
"resource": "thread",
"threadId": "={{ $json.message.threadId }}",
"operation": "removeLabels"
},
"credentials": {
"gmailOAuth2": {
"id": "YVZiLPppXZw84rIU",
"name": "Gmail account"
}
},
"typeVersion": 2.1
},
{
"id": "13d90021-d6b4-464c-bbf4-d2866e4452b8",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-800,
-280
],
"parameters": {
"width": 660,
"height": 1700,
"content": "## 使用 AI + QuickBooks 自动从带标签的邮件创建和草拟发票"
},
"typeVersion": 1
},
{
"id": "124c54fc-301d-48dc-8569-083ae9350cbf",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-100,
-160
],
"parameters": {
"color": 7,
"height": 360,
"content": "## 计划"
},
"typeVersion": 1
},
{
"id": "3657dde0-5110-4ea8-95bc-0301e9da5045",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
160,
-160
],
"parameters": {
"color": 7,
"height": 360,
"content": "## Gmail"
},
"typeVersion": 1
},
{
"id": "4d6af4d6-99a3-418b-9e05-7364ae71df30",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
420,
-160
],
"parameters": {
"color": 7,
"height": 360,
"content": "## 合并所有消息"
},
"typeVersion": 1
},
{
"id": "1adecc9c-446b-4f4d-a9dd-c333773ca0e3",
"name": "合并会话中的所有消息",
"type": "n8n-nodes-base.code",
"position": [
480,
40
],
"parameters": {
"jsCode": "const threads = {};\n\nfor (const item of items) {\n const msg = item.json;\n const threadId = msg.threadId;\n\n if (!threads[threadId]) {\n threads[threadId] = [];\n }\n\n // Add To and From Addresses\n let finalMessage = \"From: \" + msg.headers.from;\n finalMessage += \"To: \" + msg.headers.to;\n finalMessage += \"Message: \" + msg.textAsHtml\n\n threads[threadId].push(finalMessage);\n}\n\nreturn Object.keys(threads).map(threadId => ({\n json: {\n threadId,\n chatInput: threads[threadId],\n }\n}));\n"
},
"typeVersion": 2
},
{
"id": "276e3175-c11a-4ae9-94ab-9703e20b89bf",
"name": "便签说明4",
"type": "n8n-nodes-base.stickyNote",
"position": [
20,
300
],
"parameters": {
"color": 7,
"width": 440,
"height": 560,
"content": "## AI 代理:提取客户和发票详细信息"
},
"typeVersion": 1
},
{
"id": "de08bb58-b868-4c70-80b9-b63c5f607856",
"name": "便签说明5",
"type": "n8n-nodes-base.stickyNote",
"position": [
480,
300
],
"parameters": {
"color": 7,
"height": 380,
"content": "## 将客户添加到 QBO"
},
"typeVersion": 1
},
{
"id": "3344c904-9c17-4cf0-9d15-bbf1ce4d856d",
"name": "便签 6",
"type": "n8n-nodes-base.stickyNote",
"position": [
740,
300
],
"parameters": {
"color": 7,
"height": 380,
"content": "## 查找现有客户"
},
"typeVersion": 1
},
{
"id": "88e1b763-ca25-4e0e-8881-d03d32003f14",
"name": "便签 7",
"type": "n8n-nodes-base.stickyNote",
"position": [
1000,
300
],
"parameters": {
"color": 7,
"height": 380,
"content": "## 创建新发票"
},
"typeVersion": 1
},
{
"id": "cb087959-e777-4749-b734-d31ed64c09c1",
"name": "## 为什么选择 4o 模型?👆",
"type": "n8n-nodes-base.stickyNote",
"position": [
600,
760
],
"parameters": {
"color": 7,
"height": 360,
"content": "## 下载发票"
},
"typeVersion": 1
},
{
"id": "b7a83ee4-678a-4477-9b54-a21dd6099412",
"name": "便签 9",
"type": "n8n-nodes-base.stickyNote",
"position": [
860,
760
],
"parameters": {
"color": 7,
"height": 360,
"content": "## 撰写给客户的草稿回复"
},
"typeVersion": 1
},
{
"id": "4faa7895-c3dd-4607-9f55-35ee5e19728e",
"name": "便签10",
"type": "n8n-nodes-base.stickyNote",
"position": [
1120,
760
],
"parameters": {
"color": 7,
"height": 360,
"content": "## 移除\"需要发票\"标签"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Download Invoice": {
"main": [
[
{
"node": "Write Draft Reply to Client",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "Get Messages w/ Invoice Needed Label",
"type": "main",
"index": 0
}
]
]
},
"Add Client to QBO": {
"main": [
[
{
"node": "Find Existing Customer",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent: Extract Customer & Invoice Details",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Create A New Invoice": {
"main": [
[
{
"node": "Download Invoice",
"type": "main",
"index": 0
}
]
]
},
"Find Existing Customer": {
"main": [
[
{
"node": "Create A New Invoice",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "AI Agent: Extract Customer & Invoice Details",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Write Draft Reply to Client": {
"main": [
[
{
"node": "Remove Invoice Needed Label",
"type": "main",
"index": 0
}
]
]
},
"Combine all Messages in a Thread": {
"main": [
[
{
"node": "AI Agent: Extract Customer & Invoice Details",
"type": "main",
"index": 0
}
]
]
},
"Get Messages w/ Invoice Needed Label": {
"main": [
[
{
"node": "Combine all Messages in a Thread",
"type": "main",
"index": 0
}
]
]
},
"AI Agent: Extract Customer & Invoice Details": {
"main": [
[
{
"node": "Add Client to QBO",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 发票处理, AI 摘要总结
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
AI 自动保存 Gmail 收据
AI自动保存Gmail收据到Google表格和Google云端硬盘
Set
Gmail
Merge
+8
14 节点Matt Chong
发票处理
发票提醒:Gmail到Tasks
使用Gmail和Google Tasks自动检测发票并创建提醒
If
Gmail
Google Tasks
+6
13 节点Matt Chong
发票处理
发送定时n8n发布说明通知到Gmail
基于AI的n8n发布说明摘要通知(通过Gmail与GPT-5-Mini)
Set
Code
Html
+7
16 节点Jeff Huera
个人效率
23 分析客户终身价值
使用GPT-4和Bright Data MCP分析与定位高价值客户
If
Set
Code
+9
20 节点Yaron Been
市场调研
分析区域绩效
使用Bright Data MCP和GPT-4o分析销售区域绩效
Set
Code
Gmail
+8
17 节点Yaron Been
客户关系管理
16 监控竞争对手定价
基于Bright Data MCP和Google表格的竞争对手定价自动监控
Set
Code
Gmail
+8
18 节点Yaron Been
市场调研