8
n8n 中文网amn8n.com

通过API端点导出Odoo公司数据,支持JSON/Excel输出选项

高级

这是一个CRM领域的自动化工作流,包含 18 个节点。主要使用 If, Code, Odoo, Webhook, Function 等节点。 通过API端点导出Odoo公司数据,支持JSON/Excel输出选项

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "6b3e8c6c30cdfbf06283a3fa57016932c6b4ec959896c5c546ef5865ff697ff1"
  },
  "nodes": [
    {
      "id": "2b167f16-af65-4d8f-9a83-3dff9c06f99c",
      "name": "接收公司请求",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -624,
        1424
      ],
      "webhookId": "get-companies-uuid",
      "parameters": {
        "path": "/api/v1/get-companies",
        "options": {},
        "responseMode": "responseNode"
      },
      "typeVersion": 2.1
    },
    {
      "id": "b73f4dcc-6335-4458-a5d5-b6fa578dfed2",
      "name": "准备动态筛选器",
      "type": "n8n-nodes-base.function",
      "position": [
        -384,
        1424
      ],
      "parameters": {
        "functionCode": "// const query = $json[\"query\"] || {}\n// const filters = []\n// if (query.name) filters.push([\"name\", \"ilike\", query.name])\n// if (query.country) filters.push([\"country_code\", \"=\", query.country])\n// const limit = query.limit ? parseInt(query.limit) : 25\n// const response_format = query.response_format || 'json'\n// return [{ json: { filters, limit, response_format } }]\n\nconst query = $json[\"query\"] || {};\n\n// Validate required 'name' parameter\nif (!query.name || query.name.trim() === \"\") {\n  return [\n    {\n      json: {\n        success: false,\n        message: \"Missing required parameter: name\",\n      },\n    },\n  ];\n}\n\nconst filters = [];\nfilters.push([\"name\", \"ilike\", query.name]); // name is mandatory\n\nconst response_format = query.response_format || \"json\";\n\nreturn [\n  {\n    json: { filters, response_format },\n  },\n];"
      },
      "typeVersion": 1
    },
    {
      "id": "5676cb5c-2ddd-46fa-88d3-3902a183f227",
      "name": "从 Odoo 获取公司",
      "type": "n8n-nodes-base.odoo",
      "position": [
        -128,
        1424
      ],
      "parameters": {
        "options": {
          "fieldsList": [
            "display_name",
            "name",
            "email",
            "phone",
            "mobile",
            "parent_id",
            "partner_id",
            "country_code",
            "country_id"
          ]
        },
        "resource": "custom",
        "operation": "getAll",
        "returnAll": true,
        "filterRequest": {
          "filter": [
            {
              "value": "={{ $json.filters[0][2] && $json.filters[0][2].toString().trim() !== '' ? $json.filters[0][2] : \"False\" }}",
              "operator": "like",
              "fieldName": "name"
            }
          ]
        },
        "customResource": "res.company"
      },
      "credentials": {
        "odooApi": {
          "id": "rhW7JbaWT0NTawBZ",
          "name": "IMM Odoo 18"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "288b5309-6f46-484f-9ab6-06e94bd7b74f",
      "name": "准备输出数据",
      "type": "n8n-nodes-base.function",
      "position": [
        176,
        1424
      ],
      "parameters": {
        "functionCode": "if (items.length === 0 || Object.keys(items[0].json).length === 0) {\n  return [{ json: { success: false, message: 'No matching company records found' } }]\n}\nconst data = items.map(item => ({ ...item.json, report_generated_on: new Date().toISOString() }))\nreturn data.map(d => ({ json: d }))"
      },
      "typeVersion": 1
    },
    {
      "id": "cd151c5b-55ec-454a-b43d-b78a39b74441",
      "name": "检查是否需要 Excel",
      "type": "n8n-nodes-base.if",
      "position": [
        480,
        1424
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $('Prepare Dynamic Filter').item.json.response_format }}",
              "value2": "excel"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6b9e1c86-81c3-475a-bdda-1a44bc9aed4e",
      "name": "转换为 Excel",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        1104,
        1376
      ],
      "parameters": {
        "options": {},
        "operation": "xlsx"
      },
      "typeVersion": 1.1
    },
    {
      "id": "38164711-9c8c-4f7c-8e3b-3f19b1c12360",
      "name": "用文件响应",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        1392,
        1376
      ],
      "parameters": {
        "options": {},
        "respondWith": "binary"
      },
      "typeVersion": 1.4
    },
    {
      "id": "cba096d5-0e19-4bec-930e-eefe587e996e",
      "name": "用 JSON 响应",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        784,
        1776
      ],
      "parameters": {
        "options": {},
        "respondWith": "allIncomingItems"
      },
      "typeVersion": 1.4
    },
    {
      "id": "5f3f46b8-330a-4594-8170-6b2e8d68b685",
      "name": "概述说明",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1600,
        592
      ],
      "parameters": {
        "width": 900,
        "height": 572,
        "content": "## 工作原理"
      },
      "typeVersion": 1
    },
    {
      "id": "c495e6f3-9186-41ec-8994-28ba95bde11b",
      "name": "代码",
      "type": "n8n-nodes-base.code",
      "position": [
        784,
        1392
      ],
      "parameters": {
        "jsCode": "return $input.all()"
      },
      "typeVersion": 2
    },
    {
      "id": "d29068b1-e243-420b-b00c-24f9ecaa0512",
      "name": "概述说明10",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -688,
        1184
      ],
      "parameters": {
        "color": 7,
        "width": 452,
        "height": 428,
        "content": "## 请求与验证"
      },
      "typeVersion": 1
    },
    {
      "id": "285429ca-c751-4970-85ce-27289180f9c8",
      "name": "概述说明11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -208,
        1184
      ],
      "parameters": {
        "color": 7,
        "width": 276,
        "height": 428,
        "content": "## 从 Odoo 搜索记录"
      },
      "typeVersion": 1
    },
    {
      "id": "5f9b217d-9cf1-4a7d-b99a-c6640d38399b",
      "name": "概述说明12",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        1184
      ],
      "parameters": {
        "color": 7,
        "width": 276,
        "height": 428,
        "content": "## 准备数据并管理响应 JSON 对象。"
      },
      "typeVersion": 1
    },
    {
      "id": "e7a97e7d-928b-4ec3-88c7-d6a2ecee9ea9",
      "name": "概述说明13",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        400,
        1184
      ],
      "parameters": {
        "color": 7,
        "width": 276,
        "height": 428,
        "content": "## 检查 response_format"
      },
      "typeVersion": 1
    },
    {
      "id": "2d754c32-7a53-4a43-a49e-8ccf8839f6f8",
      "name": "概述说明14",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        1184
      ],
      "parameters": {
        "color": 7,
        "width": 276,
        "height": 428,
        "content": "## 为二进制文件准备数据。"
      },
      "typeVersion": 1
    },
    {
      "id": "0edb17ef-3bac-42fc-835d-d67e26ad82b0",
      "name": "概述说明15",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1008,
        1184
      ],
      "parameters": {
        "color": 7,
        "width": 276,
        "height": 428,
        "content": "## 创建 Excel 文件"
      },
      "typeVersion": 1
    },
    {
      "id": "6ab323ca-5cc5-4d86-b32d-17f7340a4ab2",
      "name": "概述说明16",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1312,
        1184
      ],
      "parameters": {
        "color": 7,
        "width": 276,
        "height": 428,
        "content": "## 用 Excel 文件响应 Webhook。"
      },
      "typeVersion": 1
    },
    {
      "id": "9d469fdf-7eaa-452f-874a-552299170c51",
      "name": "概述说明17",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        1632
      ],
      "parameters": {
        "color": 7,
        "width": 276,
        "height": 380,
        "content": "## 用 JSON 对象响应 Webhook。"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Code": {
      "main": [
        [
          {
            "node": "Convert to Excel",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to Excel": {
      "main": [
        [
          {
            "node": "Respond with File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Output Data": {
      "main": [
        [
          {
            "node": "Check If Excel Required",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Dynamic Filter": {
      "main": [
        [
          {
            "node": "Fetch Companies from Odoo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If Excel Required": {
      "main": [
        [
          {
            "node": "Code",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Respond with JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Company Request": {
      "main": [
        [
          {
            "node": "Prepare Dynamic Filter",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Companies from Odoo": {
      "main": [
        [
          {
            "node": "Prepare Output Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 客户关系管理

需要付费吗?

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

工作流信息
难度等级
高级
节点数量18
分类1
节点类型8
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
V3 Code Studio

V3 Code Studio

@v3codestudio

🚀 AI & Automation Expert | n8n Creator | Workflow Specialist | Automation Specialist | V3 Code Studio I build smart automation workflows with n8n to help businesses streamline operations, save time, and increase productivity. Passionate about no-code/low-code automation and AI-driven solutions that make processes efficient, scalable, and growth-oriented.

外部链接
在 n8n.io 查看

分享此工作流