本页内容
Sommatic 文档
打开控制台

Webhook

从任何能发送 HTTP POST 的系统启动工作流。在 Webhook 触发器中创建端点,选择 test 或 prod 模式,发送 JSON,同步等待结果或异步运行,并通过 Server-Sent Events 跟踪进度。

以 Markdown 查看
在以下应用中打开

Webhook 是把工作流接到其他系统之后最简单的方式:外部系统发送 POST,Sommatic AI 以该请求为输入运行工作流, 并返回结果,或返回一个可供跟踪的运行 id。

创建端点

  1. 把 webhook.trigger(Webhook Receiver)添加为工作流的第一个节点。
  2. 打开该节点,在 Webhook URL 区域点击 Create webhook endpoint。
  3. Sommatic AI 为工作流创建两个 ingress binding,分别标记为 TEST 和 PROD,并显示它们的 URL 以及可直接复制的 curl 命令。

URL 的最后一段用于标识 binding。它最初是为工作流生成的标识符,你可以在同一区域把它改成易读的 slug。

URL

POST https://api.sommatic.ai/workflow-orchestration/trigger/webhooks/:mode/:bindingIdentifier
路径段取值
modetest 运行草稿;prod 运行默认的已发布版本。
bindingIdentifierbinding 的 id 或 slug。Sommatic AI 先按 id 查找,再按 slug 查找。

请求

可发送任意 JSON 请求体(最大 5 MB)。工作流会把完整请求作为输入:

字段内容
body你发送的 JSON。
headers请求头,名称均为小写。
query查询字符串参数。
methodPOST。

后续节点用表达式读取:

JavaScript
{{ $json.body.data.order_id }}                               // 紧接触发器的节点
{{ $('Webhook Receiver').item.json.body.data.order_id }}     // 之后的任意节点
{{ $('Webhook Receiver').item.json.headers['x-request-id'] }}

调用示例

Shell
curl -X POST "https://api.sommatic.ai/workflow-orchestration/trigger/webhooks/prod/order-intake" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "order.received",
    "data": { "order_id": "ord_abc123", "total": 129.99, "currency": "USD" }
  }'
JavaScript
const response = await fetch(
  'https://api.sommatic.ai/workflow-orchestration/trigger/webhooks/prod/order-intake',
  {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      event: 'order.received',
      data: { order_id: 'ord_abc123', total: 129.99, currency: 'USD' },
    }),
  },
);
const { success, result } = await response.json();

同步与异步

默认情况下调用是同步的:等待运行结束,返回实例、步骤和结果。

JSON
{
  "status": 200,
  "success": true,
  "message": "Operation completed successfully",
  "result": {
    "instance": { "id": "wf-flow-instance-…", "status": "completed" },
    "steps": [
      { "nodeId": "…", "operatorSlug": "webhook.trigger", "status": "success", "port": "out", "durationMs": 2 }
    ],
    "result": {
      "outcome_category": "success",
      "duration_ms": 1840,
      "final_output_envelope": { "node_id": "…", "port": "out", "payload": {} }
    }
  }
}

对于耗时较长的工作流,可在查询字符串或请求体中使用 execution_mode=async 请求异步执行。调用会立即返回运行 id:

Shell
curl -X POST "https://api.sommatic.ai/workflow-orchestration/trigger/webhooks/prod/order-intake?execution_mode=async" \
  -H "Content-Type: application/json" \
  -d '{ "event": "report.generate", "data": { "period": "2026-04" } }'
JSON
{
  "status": 200,
  "success": true,
  "message": "Operation completed successfully",
  "result": {
    "instance": { "id": "wf-flow-instance-…", "status": "running" },
    "execution_mode": "async"
  }
}

之后可通过 SSE 跟踪运行,或稍后通过执行 API(flow-instance 和 flow-instance-result)读取。

通过 SSE 跟踪进度

为工作流打开一个 Server-Sent Events 流:

Shell
curl -N "https://api.sommatic.ai/workflow-orchestration/execution/stream?flow_definition_id=<flow-definition-id>&user_identity=<your-identity>"

两个参数都是必填项。由 Webhook 启动的运行会广播给该工作流上所有已打开的流。事件如下:

事件触发时机
connected流已打开。
webhook-received一次 Webhook 调用到达工作流。
node-step-started某个节点开始运行。
node-step-progress耗时较长的节点报告了进度。
node-step-completed某个节点结束,附带端口、耗时和输出(从 error 离开时 status 为 failed)。
execution-completed运行结束,status 为 completed 或 failed。
execution-failed运行在引擎完成之前中断(例如无法连接编排器)。

已暂停的工作流

你可以按模式暂停工作流(见发布)。对已暂停工作流的 test 调用会以状态 423 被拒绝, 且不会创建运行。prod 调用会被接受,并创建状态为 paused 的运行,确保调用有据可查。

错误

消息原因
Invalid webhook mode. Use "test" or "prod"mode 路径段不是 test 或 prod。
Webhook binding not found没有 binding 使用该 id 或 slug。
No flow definition bound to this webhookbinding 没有指向任何工作流。
No published version found for this workflow对从未发布的工作流发起了 prod 调用。

下一步

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

仅安装技能包,不会自动更新;需要时重新运行即可。

npx skills add https://docs.sommatic.ai
智能体如何读取本文档