跳到主要内容

工作流程二:生成报告#

本工作流程将指导您合并多源数据、转换二进制数据、生成文件并发送通知。最终工作流程应如下图所示:

用于数据汇总与文件生成的工作流程二

用于数据汇总与文件生成的工作流程二

为简化操作,我们将工作流程拆分为三个部分。

第一部分:获取多源数据#

工作流程第一部分包含五个节点:

工作流程一:获取多源数据

工作流程一:获取多源数据

  1. 使用 HTTP请求节点 从存储公司数据的API端点获取数据。配置以下参数:
    • 方法:Get
    • URL:课程注册邮件中收到的数据集URL
    • 认证:通用凭证类型
      • 通用认证类型:请求头认证
      • 请求头认证凭证:课程注册邮件中收到的认证名称与认证值
    • 发送请求头:开启
      • 指定请求头:选择使用下方字段
      • 名称unique_id
      • :课程注册邮件中收到的唯一ID
  2. 使用 Airtable节点customers表列出数据(需提前更新regionsubregion字段)
  3. 使用 合并节点 根据customerID字段匹配并合并Airtable节点与HTTP请求节点的数据
  4. 使用 排序节点orderPrice降序排列数据

测验问题

  • 客户1对应的员工姓名是什么?
  • 客户2的订单状态是什么?
  • 最高订单金额是多少?

第二部分:生成区域销售文件#

工作流程第二部分包含四个节点:

工作流程二:生成区域销售文件

工作流程二:生成区域销售文件

  1. 使用 条件节点 筛选仅显示美洲区域的订单
  2. 使用 文件转换节点 将输入的JSON数据转换为二进制格式(进阶技巧:尝试根据orderID为每个报告命名)
  3. 使用 Gmail节点(或其他邮件节点)将文件发送至可访问的邮箱(注意:需添加包含数据属性的附件)
  4. 使用 Discord节点 在n8n Discord频道#course-level-two发送消息。配置以下参数:
    • Webhook URL:课程注册邮件中收到的Discord链接
    • 文本:"我已通过邮件发送标签ID为{label ID}的文件。我的ID:"后接课程注册邮件中的唯一ID
      注意:需将花括号{}内的文本替换为引用节点数据的表达式

测验问题

  • 美洲区域分配了多少订单?
  • 美洲区域订单总金额是多少?
  • 写入二进制文件节点返回了多少条目?

第三部分:生成总销售文件#

工作流程第三部分包含五个节点:

工作流程三:生成总销售文件

工作流程三:生成总销售文件

  1. 使用 逐项循环节点 将数据按每批5条进行分割
  2. 使用 设置节点 通过表达式引用前序节点数据并设置四个值:customerEmailcustomerRegioncustomerSinceorderPrice
  3. 使用 日期时间节点customerSince字段的日期格式转换为MM/DD/YYYY
    • 设置包含输入字段选项以保持数据完整性
  4. 使用 文件转换节点 创建CSV表格,文件名设置为表达式:{{$runIndex > 0 ? 'file_low_orders':'file_high_orders'}}
  5. 使用 Discord节点 在n8n Discord频道#course-level-two发送消息。配置以下参数:
    • Webhook URL:课程注册邮件中收到的Discord链接
    • 文本:"我已创建表格{file name}。我的ID:"后接课程注册邮件中的唯一ID
      注意:需将{file name}替换为引用前序文件转换节点数据的表达式

测验问题

  • 第一批数据中的最低订单金额是多少?
  • 客户7的格式化日期是什么?
  • 文件转换节点返回了多少条目?

查看解决方案

要检查节点配置,可复制下方JSON工作流代码并粘贴至编辑器界面:

{
"meta": {
"templateCredsSetupCompleted": true,
"instanceId": "cb484ba7b742928a2048bf8829668bed5b5ad9787579adea888f05980292a4a7"
},
"nodes": [
{
"parameters": {
"sendTo": "bart@n8n.io",
"subject": "Your TPS Reports",
"emailType": "text",
"message": "Please find your TPS report attached.",
"options": {
"attachmentsUi": {
"attachmentsBinary": [
{}
]
}
}
},
"id": "d889eb42-8b34-4718-b961-38c8e7839ea6",
"name": "Gmail",
"type": "n8n-nodes-base.gmail",
"typeVersion": 2.1,
"position": [
2100,
500
],
"credentials": {
"gmailOAuth2": {
"id": "HFesCcFcn1NW81yu",
"name": "Gmail account 7"
}
}
},
{
"parameters": {},
"id": "c0236456-40be-4f8f-a730-e56cb62b7b5c",
"name": "When clicking \"Execute workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
780,
600
]
},
{
"parameters": {
"url": "https://internal.users.n8n.cloud/webhook/level2-erp",
"authentication": "genericCredentialType",
"genericAuthType": "httpHeaderAuth",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{
"name": "unique_id",
"value": "recFIcD6UlSyxaVMQ"
}
]
},
"options": {}
},
"id": "cc106fa0-6630-4c84-aea4-a4c7a3c149e9",
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.1,
"position": [
1000,
500
],
"credentials": {
"httpHeaderAuth": {
"id": "qeHdJdqqqaTC69cm",
"name": "Course L2 Credentials"
}
}
},
{
"parameters": {
"operation": "search",
"base": {
"__rl": true,
"value": "apprtKkVasbQDbFa1",
"mode": "list",
"cachedResultName": "All your base",
"cachedResultUrl": "https://airtable.com/apprtKkVasbQDbFa1"
},
"table": {
"__rl": true,
"value": "tblInZ7jeNdlUOvxZ",
"mode": "list",
"cachedResultName": "Course L2, Workflow 1",
"cachedResultUrl": "https://airtable.com/apprtKkVasbQDbFa1/tblInZ7jeNdlUOvxZ"
},
"options": {}
},
"id": "e5ae1927-b531-401c-9cb2-ecf1f2836ba6",
"name": "Airtable",
"type": "n8n-nodes-base.airtable",
"typeVersion": 2,
"position": [
1000,
700
],
"credentials": {
"airtableTokenApi": {
"id": "MIplo6lY3AEsdf7L",
"name": "Airtable Personal Access Token account 4"
}
}
},
{
"parameters": {
"mode": "combine",
"mergeByFields": {
"values": [
{
"field1": "customerID",
"field2": "customerID"
}
]
},
"options": {}
},
"id": "1cddc984-7fca-45e0-83b8-0c502cb4c78c",
"name": "Merge",
"type": "n8n-nodes-base.merge",
"typeVersion": 2.1,
"position": [
1220,
600
]
},
{
"parameters": {
"sortFieldsUi": {
"sortField": [
{
"fieldName": "orderPrice",
"order": "descending"
}
]
},
"options": {}
},
"id": "2f55af2e-f69b-4f61-a9e5-c7eefaad93ba",
"name": "Sort",
"type": "n8n-nodes-base.sort",
"typeVersion": 1,
"position": [
1440,
600
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "d3afe65c-7c80-4caa-9d1c-33c62fbc2197",
"leftValue": "={{ $json.region }}",
"rightValue": "Americas",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "2ed874a9-5bcf-4cc9-9b52-ea503a562892",
"name": "If",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
1660,
500
]
},
{
"parameters": {
"operation": "toJson",
"mode": "each",
"options": {
"fileName": "=report_orderID_{{ $('If').item.json.orderID }}.json"
}
},
"id": "d93b4429-2200-4a84-8505-16266fedfccd",
"name": "Convert to File",
"type": "n8n-nodes-base.convertToFile",
"typeVersion": 1.1,
"position": [
1880,
500
]
},
{
"parameters": {
"authentication": "webhook",
"content": "I sent the file using email with the label ID and wrote the binary file {file name}. My ID: 123",
"options": {}
},
"id": "26f43f2c-1422-40de-9f40-dd2d80926b1c",
"name": "Discord",
"type": "n8n-nodes-base.discord",
"typeVersion": 2,
"position": [
2320,
500
],
"credentials": {
"discordWebhookApi": {
"id": "WEBrtPdoLrhlDYKr",
"name": "L2 Course Discord Webhook account"
}
}
},
{
"parameters": {
"batchSize": 5,
"options": {}
},
"id": "0fa1fbf6-fe77-4044-a445-c49a1db37dec",
"name": "Loop Over Items",
"type": "n8n-nodes-base.splitInBatches",
"typeVersion": 3,
"position": [
1660,
700
]
},
{
"parameters": {
"assignments": {
"assignments": [
{
"id": "ce839b80-c50d-48f5-9a24-bb2df6fdd2ff",
"name": "customerEmail",
"value": "={{ $json.customerEmail }}",
"type": "string"
},
{
"id": "0c613366-3808-45a2-89cc-b34c7b9f3fb7",
"name": "region",
"value": "={{ $json.region }}",
"type": "string"
},
{
"id": "0f19a88c-deb0-4119-8965-06ed62a840b2",
"name": "customerSince",
"value": "={{ $json.customerSince }}",
"type": "string"
},
{
"id": "a7e890d6-86af-4839-b5df-d2a4efe923f7",
"name": "orderPrice",
"value": "={{ $json.orderPrice }}",
"type": "number"
}
]
},
"options": {}
},
"id": "09b8584c-4ead-4007-a6cd-edaa4669a757",
"name": "Edit Fields",
"type": "n8n-nodes-base.set",
"typeVersion": 3.3,
"position": [
1880,
700
]
},
{
"parameters": {
"operation": "formatDate",
"date": "={{ $json.customerSince }}",
"options": {
"includeInputFields": true
}
},
"id": "c96fae90-e080-48dd-9bff-3e4506aafb86",
"name": "Date & Time",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 2,
"position": [
2100,
700
]
},
{
"parameters": {
"options": {
"fileName": "={{$runIndex > 0 ? 'file_low_orders':'file_high_orders'}}"
}
},
"id": "43dc8634-2f16-442b-a754-89f47c51c591",
"name": "Convert to File1",
"type": "n8n-nodes-base.convertToFile",
"typeVersion": 1.1,
"position": [
2320,
700
]
},
{
"parameters": {
"authentication": "webhook",
"content": "I created the spreadsheet {file name}. My ID: 123",
"options": {}
},
"id": "05da1c22-d1f6-4ea6-9102-f74f9ae2e9d3",
"name": "Discord1",
"type": "n8n-nodes-base.discord",
"typeVersion": 2,
"position": [
2540,
700
],
"credentials": {
"discordWebhookApi": {
"id": "WEBrtPdoLrhlDYKr",
"name": "L2 Course Discord Webhook account"
}
}
}
],
"connections": {
"Gmail": {
"main": [
[
{
"node": "Discord",
"type": "main",
"index": 0
}
]
]
},
"When clicking \"Execute workflow\"": {
"main": [
[
{
"node": "HTTP Request",
"type": "main",
"index": 0
},
{
"node": "Airtable",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 0
}
]
]
},
"Airtable": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 1
}
]
]
},
"Merge": {
"main": [
[
{
"node": "Sort",
"type": "main",
"index": 0
}
]
]
},
"Sort": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
},
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"If": {
"main": [
[
{
"node": "Convert to File",
"type": "main",
"index": 0
}
]
]
},
"Convert to File": {
"main": [
[
{
"node": "Gmail",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
null,
[
{
"node": "Edit Fields",
"type": "main",
"index": 0
}
]
]
},
"Edit Fields": {
"main": [
[
{
"node": "Date & Time",
"type": "main",
"index": 0
}
]
]
},
"Date & Time": {
"main": [
[
{
"node": "Convert to File1",
"type": "main",
"index": 0
}
]
]
},
"Convert to File1": {
"main": [
[
{
"node": "Discord1",
"type": "main",
"index": 0
}
]
]
},
"Discord1": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {}
}