8
n8n 中文网amn8n.com

DocSumo发票解析器

中级

这是一个Invoice Processing, AI Summarization领域的自动化工作流,包含 7 个节点。主要使用 Code, FormTrigger, HttpRequest, ConvertToFile 等节点。 使用DocSumo提取并结构化发票数据并导出至Excel

前置要求
  • 可能需要目标 API 的认证凭证
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "5s26gAyizRhbNI15",
  "meta": {
    "instanceId": "2d34387799014884b6bb4a0dc8b683ee92ad2bcf5aadb21177a0062d65f47540"
  },
  "name": "DocSumo发票解析器",
  "tags": [],
  "nodes": [
    {
      "id": "a35d21e3-7139-4a75-9deb-04a61e21ab20",
      "name": "表单提交时",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        40,
        -100
      ],
      "webhookId": "468f964f-3060-4d4d-a0f0-225e1d6eddac",
      "parameters": {
        "options": {},
        "formTitle": "file",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "file",
              "multipleFiles": false
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "c5ebb140-2292-424a-81e9-3438d7142673",
      "name": "HTTP 请求",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        260,
        -100
      ],
      "parameters": {
        "url": "https://app.docsumo.com/api/v1/eevee/apikey/upload/",
        "method": "POST",
        "options": {
          "redirect": {
            "redirect": {
              "followRedirects": false
            }
          }
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "type",
              "value": "invoice"
            },
            {
              "name": "file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "file"
            },
            {
              "name": "skip_review",
              "value": "true"
            }
          ]
        },
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {}
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "b76f3d26-c582-4c87-b2f7-9f973ecf6dd0",
      "name": "HTTP 请求 1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        440,
        -100
      ],
      "parameters": {
        "url": "=https://app.docsumo.com/api/v1/eevee/apikey/documents/detail/{{ $json.data.document[0].doc_id }}",
        "options": {},
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "typeVersion": 4.2
    },
    {
      "id": "78a90dab-233f-42f9-9d97-2a8220c77ceb",
      "name": "HTTP请求2",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        620,
        -100
      ],
      "parameters": {
        "url": "=https://app.docsumo.com/api/v1/eevee/apikey/data/simplified/{{ $json.data.document.doc_id }}/",
        "options": {
          "response": {
            "response": {}
          }
        },
        "sendHeaders": true,
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "headerParameters": {
          "parameters": [
            {
              "name": "accept",
              "value": "application/json"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "d5f56d5b-b7e6-41f1-9e7a-81c97eb2c191",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        780,
        -100
      ],
      "parameters": {
        "jsCode": "// Process each document item\nconst processInvoice = (doc) => {\n  // Extract header information (excluding Document Title and Processed At)\n  const headerData = {\n    \"Invoice Number\": doc?.data?.[\"Basic Information\"]?.[\"Invoice Number\"]?.value || \"\",\n    \"Issue Date\": doc?.data?.[\"Basic Information\"]?.[\"Issue Date\"]?.value || \"\",\n    \"Order ID\": doc?.data?.[\"Basic Information\"]?.[\"Order Id/Tracking No\"]?.value || \"\",\n    \"Payment Terms\": doc?.data?.[\"Basic Information\"]?.[\"Terms\"]?.value || \"\",\n    \"Buyer Name\": doc?.data?.[\"Buyer Detail\"]?.[\"Name\"]?.value || \"\",\n    \"Buyer Address\": doc?.data?.[\"Buyer Detail\"]?.[\"Address\"]?.value || \"\",\n    \"Buyer GST\": doc?.data?.[\"Buyer Detail\"]?.[\"GST/ VAT Number\"]?.value || \"\",\n    \"Seller Name\": doc?.data?.[\"Seller Detail\"]?.[\"Name\"]?.value || \"\",\n    \"Seller Address\": doc?.data?.[\"Seller Detail\"]?.[\"Address\"]?.value || \"\",\n    \"Seller GST\": doc?.data?.[\"Seller Detail\"]?.[\"GST/ VAT Number\"]?.value || \"\",\n    \"Subtotal\": doc?.data?.[\"GST & Amount\"]?.[\"Subtotal\"]?.value || 0,\n    \"Tax Total\": doc?.data?.[\"GST & Amount\"]?.[\"Tax Total\"]?.value || 0,\n    \"Total Due\": doc?.data?.[\"GST & Amount\"]?.[\"Total Due\"]?.value || 0\n  };\n\n  // Process line items with all original columns\n  return doc?.data?.Table?.[\"Line Items\"]?.map(item => ({\n    ...headerData,  // Include all header fields\n    \"Sr No.\": item?.[\"Sr No.\"]?.value || \"\",\n    \"Item Code\": item?.[\"Item Code\"]?.value || \"\",\n    \"Item Desc\": item?.Description?.value || \"\",\n    \"HSN/SAC Code\": item?.HSN?.value || \"\",\n    \"Qty\": item?.Quantity?.value || 0,\n    \"Unit Price (INR)\": item?.[\"Unit Price\"]?.value || 0,\n    \"Per\": item?.[\"Per\"]?.value || \"\",\n    \"UoM\": item?.UoM?.value || \"\",\n    \"Net Amount (INR)\": item?.[\"Subtotal Line\"]?.value || 0,\n    \"Tax Rate\": item?.[\"Tax Rate Line\"]?.value || \"\",\n    \"TGST\": item?.TGST?.value || 0,\n    \"CGST\": item?.CGST?.value || 0,\n    \"SGST\": item?.SGST?.value || 0,\n    \"TCS\": item?.TCS?.value || 0,\n    \"Gross Amt (INR)\": item?.[\"Gross Amount\"]?.value || 0,\n    \"Delivery Date\": item?.[\"Delivery Date\"]?.value || \"\"\n  })) || [];\n};\n\n// Main processing\nconst allResults = [];\nfor (const item of items) {\n  try {\n    const doc = Array.isArray(item.json) ? item.json[0] : item.json;\n    if (doc?.data) {\n      allResults.push(...processInvoice(doc));\n    }\n  } catch (error) {\n    console.log(`Error processing item: ${error.message}`);\n  }\n}\n\n// Return formatted results\nreturn allResults.length > 0 \n  ? allResults.map(result => ({ json: result }))\n  : [{ json: { error: \"No valid data processed\", raw: items[0]?.json }}];"
      },
      "typeVersion": 2
    },
    {
      "id": "ca39a45f-5ea1-40a2-a68f-49e62ead1973",
      "name": "转换为文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        980,
        -100
      ],
      "parameters": {
        "options": {},
        "operation": "xls",
        "binaryPropertyName": "="
      },
      "typeVersion": 1.1
    },
    {
      "id": "01c14879-d3f3-4185-a30c-609de127c0d7",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        720,
        40
      ],
      "parameters": {
        "height": 100,
        "content": "请调整代码:您可以通过编辑代码节点来自定义标题或行项目提取"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "2c8d10c9-6226-47ef-ad9d-9690fed6df9b",
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request": {
      "main": [
        [
          {
            "node": "HTTP Request1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request1": {
      "main": [
        [
          {
            "node": "HTTP Request2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request2": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 发票处理, AI 摘要总结

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流