创建自动化规则
curl --request POST \
--url 'https://api.flashcat.cloud/safari/automation/rule/create?app_key=' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"name": "Weekly on-call review",
"team_id": 123,
"enabled": true,
"cron_expr": "0 9 * * 1",
"timezone": "Asia/Shanghai",
"schedule_trigger_enabled": true,
"prompt": "Summarize last week's alert noise and escalation load.",
"http_post_trigger_enabled": true,
"oncall_incident_trigger_enabled": true,
"oncall_incident_channel_ids": [
456
],
"oncall_incident_severities": [
"Critical",
"Warning"
]
}
EOFimport requests
url = "https://api.flashcat.cloud/safari/automation/rule/create?app_key="
payload = {
"name": "Weekly on-call review",
"team_id": 123,
"enabled": True,
"cron_expr": "0 9 * * 1",
"timezone": "Asia/Shanghai",
"schedule_trigger_enabled": True,
"prompt": "Summarize last week's alert noise and escalation load.",
"http_post_trigger_enabled": True,
"oncall_incident_trigger_enabled": True,
"oncall_incident_channel_ids": [456],
"oncall_incident_severities": ["Critical", "Warning"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Weekly on-call review',
team_id: 123,
enabled: true,
cron_expr: '0 9 * * 1',
timezone: 'Asia/Shanghai',
schedule_trigger_enabled: true,
prompt: 'Summarize last week\'s alert noise and escalation load.',
http_post_trigger_enabled: true,
oncall_incident_trigger_enabled: true,
oncall_incident_channel_ids: [456],
oncall_incident_severities: ['Critical', 'Warning']
})
};
fetch('https://api.flashcat.cloud/safari/automation/rule/create?app_key=', 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.flashcat.cloud/safari/automation/rule/create?app_key=",
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([
'name' => 'Weekly on-call review',
'team_id' => 123,
'enabled' => true,
'cron_expr' => '0 9 * * 1',
'timezone' => 'Asia/Shanghai',
'schedule_trigger_enabled' => true,
'prompt' => 'Summarize last week\'s alert noise and escalation load.',
'http_post_trigger_enabled' => true,
'oncall_incident_trigger_enabled' => true,
'oncall_incident_channel_ids' => [
456
],
'oncall_incident_severities' => [
'Critical',
'Warning'
]
]),
CURLOPT_HTTPHEADER => [
"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.flashcat.cloud/safari/automation/rule/create?app_key="
payload := strings.NewReader("{\n \"name\": \"Weekly on-call review\",\n \"team_id\": 123,\n \"enabled\": true,\n \"cron_expr\": \"0 9 * * 1\",\n \"timezone\": \"Asia/Shanghai\",\n \"schedule_trigger_enabled\": true,\n \"prompt\": \"Summarize last week's alert noise and escalation load.\",\n \"http_post_trigger_enabled\": true,\n \"oncall_incident_trigger_enabled\": true,\n \"oncall_incident_channel_ids\": [\n 456\n ],\n \"oncall_incident_severities\": [\n \"Critical\",\n \"Warning\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
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.flashcat.cloud/safari/automation/rule/create?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Weekly on-call review\",\n \"team_id\": 123,\n \"enabled\": true,\n \"cron_expr\": \"0 9 * * 1\",\n \"timezone\": \"Asia/Shanghai\",\n \"schedule_trigger_enabled\": true,\n \"prompt\": \"Summarize last week's alert noise and escalation load.\",\n \"http_post_trigger_enabled\": true,\n \"oncall_incident_trigger_enabled\": true,\n \"oncall_incident_channel_ids\": [\n 456\n ],\n \"oncall_incident_severities\": [\n \"Critical\",\n \"Warning\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/safari/automation/rule/create?app_key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Weekly on-call review\",\n \"team_id\": 123,\n \"enabled\": true,\n \"cron_expr\": \"0 9 * * 1\",\n \"timezone\": \"Asia/Shanghai\",\n \"schedule_trigger_enabled\": true,\n \"prompt\": \"Summarize last week's alert noise and escalation load.\",\n \"http_post_trigger_enabled\": true,\n \"oncall_incident_trigger_enabled\": true,\n \"oncall_incident_channel_ids\": [\n 456\n ],\n \"oncall_incident_severities\": [\n \"Critical\",\n \"Warning\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"rule_id": "arule_7NnLzY2Qp8xS4kUaV3mR6b",
"account_id": 10023,
"team_id": 123,
"owner_id": 80011,
"name": "Weekly on-call review",
"enabled": true,
"run_scope": "team",
"cron_expr": "0 9 * * 1",
"timezone": "Asia/Shanghai",
"prompt": "Summarize last week's alert noise and escalation load.",
"environment_kind": "",
"environment_id": "",
"schedule_trigger_id": "atrig_6aKp3wT9mQ2xVc8bR1nY7z",
"schedule_trigger_enabled": true,
"http_post_trigger_id": "atrig_2bLq4xT8mP1sWd9cN3rF6y",
"http_post_trigger_url": "/safari/automation/triggers/atrig_2bLq4xT8mP1sWd9cN3rF6y/fire",
"http_post_trigger_enabled": true,
"can_edit": true,
"created_at": 1780367971228,
"updated_at": 1780367971228,
"http_post_token": "sat_yQ9p8V7n6M5k4J3h2G1f0E9d8C7b6A5z4Y3x2W1v0U",
"schedule_next_fire_at_ms": 1780630800000,
"oncall_incident_trigger_id": "atrig_9cVb2mN7qKs4dEa8T1rY5p",
"oncall_incident_trigger_enabled": true,
"oncall_incident_channel_ids": [
456
],
"oncall_incident_severities": [
"Critical",
"Warning"
],
"oncall_incident_merge_similar": true,
"war_room_trigger_enabled": false,
"execution_place": "web_console",
"execution_location": {
"place": "web_console",
"run_scope": "team",
"team_id": 123,
"description": "Web console"
}
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter skill_id is not valid."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "Unauthorized",
"message": "You are unauthorized."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "AccessDenied",
"message": "Access Denied."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "RequestTooFrequently",
"message": "Request too frequently."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InternalError",
"message": "We encountered an internal error, and it has been reported. Please try again later."
}
}自动化
创建自动化规则
创建自动化规则,可配置定时、HTTP POST、On-call 故障和作战室触发器。
POST
/
safari
/
automation
/
rule
/
create
创建自动化规则
curl --request POST \
--url 'https://api.flashcat.cloud/safari/automation/rule/create?app_key=' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"name": "Weekly on-call review",
"team_id": 123,
"enabled": true,
"cron_expr": "0 9 * * 1",
"timezone": "Asia/Shanghai",
"schedule_trigger_enabled": true,
"prompt": "Summarize last week's alert noise and escalation load.",
"http_post_trigger_enabled": true,
"oncall_incident_trigger_enabled": true,
"oncall_incident_channel_ids": [
456
],
"oncall_incident_severities": [
"Critical",
"Warning"
]
}
EOFimport requests
url = "https://api.flashcat.cloud/safari/automation/rule/create?app_key="
payload = {
"name": "Weekly on-call review",
"team_id": 123,
"enabled": True,
"cron_expr": "0 9 * * 1",
"timezone": "Asia/Shanghai",
"schedule_trigger_enabled": True,
"prompt": "Summarize last week's alert noise and escalation load.",
"http_post_trigger_enabled": True,
"oncall_incident_trigger_enabled": True,
"oncall_incident_channel_ids": [456],
"oncall_incident_severities": ["Critical", "Warning"]
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
name: 'Weekly on-call review',
team_id: 123,
enabled: true,
cron_expr: '0 9 * * 1',
timezone: 'Asia/Shanghai',
schedule_trigger_enabled: true,
prompt: 'Summarize last week\'s alert noise and escalation load.',
http_post_trigger_enabled: true,
oncall_incident_trigger_enabled: true,
oncall_incident_channel_ids: [456],
oncall_incident_severities: ['Critical', 'Warning']
})
};
fetch('https://api.flashcat.cloud/safari/automation/rule/create?app_key=', 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.flashcat.cloud/safari/automation/rule/create?app_key=",
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([
'name' => 'Weekly on-call review',
'team_id' => 123,
'enabled' => true,
'cron_expr' => '0 9 * * 1',
'timezone' => 'Asia/Shanghai',
'schedule_trigger_enabled' => true,
'prompt' => 'Summarize last week\'s alert noise and escalation load.',
'http_post_trigger_enabled' => true,
'oncall_incident_trigger_enabled' => true,
'oncall_incident_channel_ids' => [
456
],
'oncall_incident_severities' => [
'Critical',
'Warning'
]
]),
CURLOPT_HTTPHEADER => [
"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.flashcat.cloud/safari/automation/rule/create?app_key="
payload := strings.NewReader("{\n \"name\": \"Weekly on-call review\",\n \"team_id\": 123,\n \"enabled\": true,\n \"cron_expr\": \"0 9 * * 1\",\n \"timezone\": \"Asia/Shanghai\",\n \"schedule_trigger_enabled\": true,\n \"prompt\": \"Summarize last week's alert noise and escalation load.\",\n \"http_post_trigger_enabled\": true,\n \"oncall_incident_trigger_enabled\": true,\n \"oncall_incident_channel_ids\": [\n 456\n ],\n \"oncall_incident_severities\": [\n \"Critical\",\n \"Warning\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
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.flashcat.cloud/safari/automation/rule/create?app_key=")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Weekly on-call review\",\n \"team_id\": 123,\n \"enabled\": true,\n \"cron_expr\": \"0 9 * * 1\",\n \"timezone\": \"Asia/Shanghai\",\n \"schedule_trigger_enabled\": true,\n \"prompt\": \"Summarize last week's alert noise and escalation load.\",\n \"http_post_trigger_enabled\": true,\n \"oncall_incident_trigger_enabled\": true,\n \"oncall_incident_channel_ids\": [\n 456\n ],\n \"oncall_incident_severities\": [\n \"Critical\",\n \"Warning\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.flashcat.cloud/safari/automation/rule/create?app_key=")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Weekly on-call review\",\n \"team_id\": 123,\n \"enabled\": true,\n \"cron_expr\": \"0 9 * * 1\",\n \"timezone\": \"Asia/Shanghai\",\n \"schedule_trigger_enabled\": true,\n \"prompt\": \"Summarize last week's alert noise and escalation load.\",\n \"http_post_trigger_enabled\": true,\n \"oncall_incident_trigger_enabled\": true,\n \"oncall_incident_channel_ids\": [\n 456\n ],\n \"oncall_incident_severities\": [\n \"Critical\",\n \"Warning\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"data": {
"rule_id": "arule_7NnLzY2Qp8xS4kUaV3mR6b",
"account_id": 10023,
"team_id": 123,
"owner_id": 80011,
"name": "Weekly on-call review",
"enabled": true,
"run_scope": "team",
"cron_expr": "0 9 * * 1",
"timezone": "Asia/Shanghai",
"prompt": "Summarize last week's alert noise and escalation load.",
"environment_kind": "",
"environment_id": "",
"schedule_trigger_id": "atrig_6aKp3wT9mQ2xVc8bR1nY7z",
"schedule_trigger_enabled": true,
"http_post_trigger_id": "atrig_2bLq4xT8mP1sWd9cN3rF6y",
"http_post_trigger_url": "/safari/automation/triggers/atrig_2bLq4xT8mP1sWd9cN3rF6y/fire",
"http_post_trigger_enabled": true,
"can_edit": true,
"created_at": 1780367971228,
"updated_at": 1780367971228,
"http_post_token": "sat_yQ9p8V7n6M5k4J3h2G1f0E9d8C7b6A5z4Y3x2W1v0U",
"schedule_next_fire_at_ms": 1780630800000,
"oncall_incident_trigger_id": "atrig_9cVb2mN7qKs4dEa8T1rY5p",
"oncall_incident_trigger_enabled": true,
"oncall_incident_channel_ids": [
456
],
"oncall_incident_severities": [
"Critical",
"Warning"
],
"oncall_incident_merge_similar": true,
"war_room_trigger_enabled": false,
"execution_place": "web_console",
"execution_location": {
"place": "web_console",
"run_scope": "team",
"team_id": 123,
"description": "Web console"
}
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InvalidParameter",
"message": "The specified parameter skill_id is not valid."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "Unauthorized",
"message": "You are unauthorized."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "AccessDenied",
"message": "Access Denied."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "RequestTooFrequently",
"message": "Request too frequently."
}
}{
"request_id": "01HK8XQE3Z7JM2NTFQ5YJ8P9R4",
"error": {
"code": "InternalError",
"message": "We encountered an internal error, and it has been reported. Please try again later."
}
}限制说明
| 项目 | 说明 |
|---|---|
| 速率限制 | 每个账户 300 次/分钟;20 次/秒 |
| 权限要求 | Automation 管理(ai-sre) |
使用说明
- 传
0创建个人规则。使用 App Key 且省略team_id时同样创建个人规则。创建团队规则要求调用者是该团队成员,账户所有者和管理员也不例外。 - 规则的作用域在创建时确定:更新自动化规则时,
team_id与已存值不同会被拒绝。如需在其他作用域运行同一任务,请新建规则。 - 即使只使用其他触发器,
cron_expr也必填;请传一个合法表达式并将schedule_trigger_enabled设为false。 cron_expr按timezone计算;未提供时依次使用调用者的成员时区、账户时区,最后为Asia/Shanghai。http_post_trigger_enabled=true会创建并启用 HTTP POST 触发器。http_post_token只在本次响应中返回,请妥善保存。触发方式:向http_post_trigger_url发送POST,并带请求头Authorization: Bearer <http_post_token>;可选的 JSON 请求体{"text": "..."}不超过 256 KB。- 只要传了任一
oncall_incident_*字段,oncall_incident_channel_ids与oncall_incident_severities都必须非空。命中条件的故障会以trigger_kind=oncall_incident发起运行。 - 当
war_room_trigger_enabled=true或传了war_room_channel_ids时,war_room_channel_ids与war_room_severities都必须非空。命中条件的故障创建作战室(IM 群聊)后,Agent 会直接在该群聊中运行,运行记录的trigger_kind为war_room_created。 - 通过 API 创建的规则在 Web 控制台中运行(
execution_place=web_console);run_in=current-chat仅在与 AI SRE Agent 的实时 IM 会话中可用,通过 API 传入会被拒绝。 - 响应为新建的规则;对创建者而言
can_edit恒为true。 - 每次调用都会记录到账户审计日志。
授权
请求体
application/json
创建自动化规则。
响应
成功
所有 Flashduty 公开 API 共用的标准响应结构。成功时 data 为接口专属载荷且不含 error;失败时 error 存在而 data 缺失。request_id 始终存在,并会同步写入 Flashcat-Request-Id 响应头。
此页面对您有帮助吗?