8
n8n 中文网amn8n.com

使用Jotform、Xero和Gmail为客户生成发票

中级

这是一个自动化工作流,包含 13 个节点。主要使用 Code, Xero, Gmail, Webhook, Agent 等节点。 使用Jotform、Xero和GPT驱动的邮件生成专业发票

前置要求
  • Google 账号和 Gmail API 凭证
  • HTTP Webhook 端点(n8n 会自动生成)
  • OpenAI API Key

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "UVDQqxGZJ1zaxyNj",
  "meta": {
    "instanceId": "3549451ca835035557d5dc1c3d9e6ba924e7314534a74c901f66b91f9ef6023e",
    "templateCredsSetupCompleted": true
  },
  "name": "使用 Jotform、Xero 和 Gmail 为客户生成发票",
  "tags": [],
  "nodes": [
    {
      "id": "065aeee4-b7de-4e08-a95e-1c4846861411",
      "name": "接收表单提交",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -464,
        0
      ],
      "webhookId": "bf87ee72-aecf-44e5-a466-3d0144da2221",
      "parameters": {
        "path": "bf87ee72-aecf-44e5-a466-3d0144da2221",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2.1
    },
    {
      "id": "4b4284d5-10b9-439e-99f0-08f9c48fc683",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -544,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 320,
        "content": "## 接收提交"
      },
      "typeVersion": 1
    },
    {
      "id": "33e3c8d0-02d4-4887-973a-106988ebe9d4",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        64,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 288,
        "height": 320,
        "content": "## 创建/更新联系人"
      },
      "typeVersion": 1
    },
    {
      "id": "dc1c4f42-d6c8-455b-9c2b-4004a990eb21",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 320,
        "content": "## 创建发票"
      },
      "typeVersion": 1
    },
    {
      "id": "aaf471ff-be4d-4bc7-9132-c45a01bdd5d1",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1328,
        -400
      ],
      "parameters": {
        "width": 736,
        "height": 832,
        "content": "## 使用 Jotform、Xero 和 Gmail 为客户生成发票"
      },
      "typeVersion": 1
    },
    {
      "id": "c391a307-3bef-45c9-8310-8110e7058a37",
      "name": "便签8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 256,
        "height": 320,
        "content": "## 格式化数据"
      },
      "typeVersion": 1
    },
    {
      "id": "7fac0a20-8cf3-4dfc-b65d-9b59444f1c61",
      "name": "格式化数据",
      "type": "n8n-nodes-base.code",
      "position": [
        -160,
        0
      ],
      "parameters": {
        "jsCode": "function extractAddressData(text) {\n  const regex = /Street Address:\\s*([^<]+)<br>Street Address Line 2:\\s*([^<]+)<br>City:\\s*([^<]+)<br>State \\/ Province:\\s*([^<]+)<br>Postal \\/ Zip Code:\\s*([^<]+)<br>Country:\\s*([^<]+)<br>/;\n  const matches = text.match(regex);\n  \n  if (matches) {\n    return {\n      line1: matches[1].trim(),\n      line2: matches[2].trim(),\n      city: matches[3].trim(),\n      stateProvince: matches[4].trim(),\n      postalZipCode: matches[5].trim(),\n      country: matches[6].trim()\n    };\n  }\n  \n  return {\n    line1: null,\n    line2: null,\n    city: null,\n    stateProvince: null,\n    postalZipCode: null,\n    country: null\n  }\n}\n\nreturn {\n  address: extractAddressData($input.first().json.body.billingAddress),\n  customer: {\n    name: $input.first().json.body.name,\n    email: $input.first().json.body.email,\n    phone: $input.first().json.body.phone\n  },\n  item: {\n    name: $input.first().json.body.itemName\n  }\n}"
      },
      "typeVersion": 2
    },
    {
      "id": "28d16066-551a-4205-b24d-4759d02d881e",
      "name": "创建/更新联系人",
      "type": "n8n-nodes-base.xero",
      "position": [
        160,
        0
      ],
      "parameters": {
        "name": "={{ $json.customer.name }}",
        "resource": "contact",
        "organizationId": "bc9a44a6-eb14-4f81-b24c-ca676c506446",
        "additionalFields": {
          "phonesUi": {
            "phonesValues": [
              {
                "phoneType": "MOBILE",
                "phoneNumber": "={{ $json.customer.phone }}"
              }
            ]
          },
          "addressesUi": {
            "addressesValues": [
              {
                "city": "={{ $json.address.city }}",
                "type": "STREET",
                "line1": "={{ $json.address.line1 }}",
                "line2": "={{ $json.address.line2 }}",
                "region": "={{ $json.address.stateProvince }}",
                "country": "={{ $json.address.country }}",
                "postalCode": "={{ $json.address.postalZipCode }}"
              }
            ]
          },
          "emailAddress": "={{ $json.customer.email }}"
        }
      },
      "credentials": {
        "xeroOAuth2Api": {
          "id": "HZnbTfrr5leqrLUQ",
          "name": "Xero account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "46594f4d-9682-4298-a366-40bcb54c9ccb",
      "name": "创建发票",
      "type": "n8n-nodes-base.xero",
      "position": [
        480,
        0
      ],
      "parameters": {
        "type": "ACCREC",
        "contactId": "={{ $json.ContactID }}",
        "lineItemsUi": {
          "lineItemsValues": [
            {
              "taxType": "INPUT",
              "itemCode": "={{ $('Format data').item.json.item.name }}",
              "unitAmount": "10",
              "accountCode": "200"
            }
          ]
        },
        "organizationId": "bc9a44a6-eb14-4f81-b24c-ca676c506446",
        "additionalFields": {}
      },
      "credentials": {
        "xeroOAuth2Api": {
          "id": "HZnbTfrr5leqrLUQ",
          "name": "Xero account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3b291d2e-a98a-474e-aaf2-8edd4bd734f1",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        816,
        -64
      ],
      "parameters": {
        "text": "={{ $json }}",
        "options": {
          "systemMessage": "=You are an AI assistant that generates a professional invoice email that you get from an Xero response (newly created invoice), so you will recive an Xero invoice response and thus your job is to create a professional html email content because this html email content will be sent to the customer."
        },
        "promptType": "define"
      },
      "executeOnce": false,
      "typeVersion": 2.2
    },
    {
      "id": "d770459b-7a80-4abb-8609-aece00840acb",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        816,
        144
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini",
          "cachedResultName": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "ns8LVe1zpSS3Kw9p",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ce21e6a5-1657-49ec-979e-d14c7f578364",
      "name": "便签19",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -192
      ],
      "parameters": {
        "color": 7,
        "width": 592,
        "height": 480,
        "content": "## 发送发票"
      },
      "typeVersion": 1
    },
    {
      "id": "d661fc32-c68c-463d-b815-2f342a3ac011",
      "name": "发送邮件",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1088,
        -64
      ],
      "webhookId": "34d9e2cd-ada9-43de-b476-36ae61b9ff32",
      "parameters": {
        "sendTo": "={{ $('Create the invoice').item.json.Contact.EmailAddress }}",
        "message": "={{ $json.output }}",
        "options": {},
        "subject": "New Invoice"
      },
      "typeVersion": 2.1
    }
  ],
  "active": false,
  "pinData": {
    "Receive form submission": [
      {
        "json": {
          "body": {
            "name": "Adrian Mathews",
            "email": "yoled82772@elygifts.com",
            "phone": "(116) 777-9916",
            "itemName": "Design",
            "billingAddress": "Street Address: Nulla quia debitis est quam facilis amet enim cupidatat officia autem consequatur qui quis dolorem<br>Street Address Line 2: Possimus perferendis ad veritatis quia animi<br>City: Voluptatibus eveniet harum unde dolor doloremque cumque dol<br>State / Province: Reprehenderit rerum voluptas magni ut minim ad deleniti eni<br>Postal / Zip Code: 17167<br>Country: Seychelles<br>"
          }
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "d514ba5d-30a5-4cfb-b09f-b1a611151c1f",
  "connections": {
    "3b291d2e-a98a-474e-aaf2-8edd4bd734f1": {
      "main": [
        [
          {
            "node": "d661fc32-c68c-463d-b815-2f342a3ac011",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "7fac0a20-8cf3-4dfc-b65d-9b59444f1c61": {
      "main": [
        [
          {
            "node": "28d16066-551a-4205-b24d-4759d02d881e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "d770459b-7a80-4abb-8609-aece00840acb": {
      "ai_languageModel": [
        [
          {
            "node": "3b291d2e-a98a-474e-aaf2-8edd4bd734f1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "46594f4d-9682-4298-a366-40bcb54c9ccb": {
      "main": [
        [
          {
            "node": "3b291d2e-a98a-474e-aaf2-8edd4bd734f1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "065aeee4-b7de-4e08-a95e-1c4846861411": {
      "main": [
        [
          {
            "node": "7fac0a20-8cf3-4dfc-b65d-9b59444f1c61",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "28d16066-551a-4205-b24d-4759d02d881e": {
      "main": [
        [
          {
            "node": "46594f4d-9682-4298-a366-40bcb54c9ccb",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

中级

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量13
分类-
节点类型7
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流

分类

分类: 34