创建 Webhook
创建一个处于禁用状态的 Webhook,并返回签名密钥。保存密钥并配置接收端后,再启用 Webhook。每个项目最多有 32 个 Webhook,包含已禁用的 Webhook;超出上限返回 400 failed_precondition_error。多个 Webhook 可以使用同一地址。
POST
/
v1
/
webhooks
创建 Webhook
curl --request POST \
--url https://api.moonshot.cn/v1/webhooks \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://example.invalid/hook",
"event_types": [
"agent.updated",
"session.status_idled"
]
}
'import requests
url = "https://api.moonshot.cn/v1/webhooks"
payload = {
"url": "https://example.invalid/hook",
"event_types": ["agent.updated", "session.status_idled"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
url: 'https://example.invalid/hook',
event_types: ['agent.updated', 'session.status_idled']
})
};
fetch('https://api.moonshot.cn/v1/webhooks', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/webhooks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://example.invalid/hook',
'event_types' => [
'agent.updated',
'session.status_idled'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/webhooks"
payload := strings.NewReader("{\n \"url\": \"https://example.invalid/hook\",\n \"event_types\": [\n \"agent.updated\",\n \"session.status_idled\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/webhooks")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://example.invalid/hook\",\n \"event_types\": [\n \"agent.updated\",\n \"session.status_idled\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/webhooks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://example.invalid/hook\",\n \"event_types\": [\n \"agent.updated\",\n \"session.status_idled\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "webhook_01h455vb4pex5vsknk084sn02q",
"name": "Production events",
"url": "https://example.invalid/hook",
"event_types": [
"agent.updated",
"session.status_idled"
],
"enabled": false,
"disabled_reason": "manual",
"created_at": "2026-11-05T00:00:00Z",
"updated_at": "2026-11-05T00:00:00Z",
"signing_secret": "whsec_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
}{
"error": {
"type": "invalid_parameter_error",
"message": "The `name` parameter is invalid.",
"request_id": "req_01h455vb4pex5vsknk084sn02q",
"param": "name"
}
}{
"error": {
"type": "authentication_error",
"message": "Provide valid credentials before retrying.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "permission_denied_error",
"message": "The caller cannot perform this operation.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "resource_not_found_error",
"message": "The requested resource does not exist.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "rate_limit_reached_error",
"message": "Too many requests. Retry after 60 seconds.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "server_error",
"message": "The platform could not complete the request. Retry later.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}请求头
请求体
application/json
新 Webhook 的配置。
新 Webhook 的配置。
订阅的业务事件类型,至少指定一项,不能重复。
Minimum array length:
1Webhook 可订阅的业务事件类型。
可用选项:
session.status_run_started, session.status_idled, session.status_terminated, session.thread_created, session.thread_idled, session.thread_terminated, session.updated, session.deleted, vault.created, vault.archived, vault.deleted, vault_credential.created, vault_credential.archived, vault_credential.deleted, vault_credential.refresh_failed, agent.created, agent.updated, agent.archived, trigger.created, trigger.updated, trigger.paused, trigger.unpaused, trigger.archived, trigger_run.started, trigger_run.succeeded, trigger_run.failed, trigger_run.skipped, environment.created, environment.updated, environment.build_ended, environment.archived, environment.deleted, memory_store.created, memory_store.archived, memory_store.deleted 示例:
["agent.updated", "session.status_idled"]
响应
Webhook 已创建。
Webhook 配置及新签名密钥。
此 Webhook 订阅的业务事件类型。
Webhook 可订阅的业务事件类型。
可用选项:
session.status_run_started, session.status_idled, session.status_terminated, session.thread_created, session.thread_idled, session.thread_terminated, session.updated, session.deleted, vault.created, vault.archived, vault.deleted, vault_credential.created, vault_credential.archived, vault_credential.deleted, vault_credential.refresh_failed, agent.created, agent.updated, agent.archived, trigger.created, trigger.updated, trigger.paused, trigger.unpaused, trigger.archived, trigger_run.started, trigger_run.succeeded, trigger_run.failed, trigger_run.skipped, environment.created, environment.updated, environment.build_ended, environment.archived, environment.deleted, memory_store.created, memory_store.archived, memory_store.deleted 示例:
["agent.updated", "session.status_idled"]
此页面对您有帮助吗?
⌘I
创建 Webhook
curl --request POST \
--url https://api.moonshot.cn/v1/webhooks \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://example.invalid/hook",
"event_types": [
"agent.updated",
"session.status_idled"
]
}
'import requests
url = "https://api.moonshot.cn/v1/webhooks"
payload = {
"url": "https://example.invalid/hook",
"event_types": ["agent.updated", "session.status_idled"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
url: 'https://example.invalid/hook',
event_types: ['agent.updated', 'session.status_idled']
})
};
fetch('https://api.moonshot.cn/v1/webhooks', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.moonshot.cn/v1/webhooks",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://example.invalid/hook',
'event_types' => [
'agent.updated',
'session.status_idled'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.moonshot.cn/v1/webhooks"
payload := strings.NewReader("{\n \"url\": \"https://example.invalid/hook\",\n \"event_types\": [\n \"agent.updated\",\n \"session.status_idled\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.moonshot.cn/v1/webhooks")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://example.invalid/hook\",\n \"event_types\": [\n \"agent.updated\",\n \"session.status_idled\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.moonshot.cn/v1/webhooks")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://example.invalid/hook\",\n \"event_types\": [\n \"agent.updated\",\n \"session.status_idled\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "webhook_01h455vb4pex5vsknk084sn02q",
"name": "Production events",
"url": "https://example.invalid/hook",
"event_types": [
"agent.updated",
"session.status_idled"
],
"enabled": false,
"disabled_reason": "manual",
"created_at": "2026-11-05T00:00:00Z",
"updated_at": "2026-11-05T00:00:00Z",
"signing_secret": "whsec_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
}{
"error": {
"type": "invalid_parameter_error",
"message": "The `name` parameter is invalid.",
"request_id": "req_01h455vb4pex5vsknk084sn02q",
"param": "name"
}
}{
"error": {
"type": "authentication_error",
"message": "Provide valid credentials before retrying.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "permission_denied_error",
"message": "The caller cannot perform this operation.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "resource_not_found_error",
"message": "The requested resource does not exist.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "rate_limit_reached_error",
"message": "Too many requests. Retry after 60 seconds.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}{
"error": {
"type": "server_error",
"message": "The platform could not complete the request. Retry later.",
"request_id": "req_01h455vb4pex5vsknk084sn02q"
}
}