> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flashduty.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 更新自动化规则

> 更新自动化规则的可变字段，包括 HTTP POST 与 On-call 故障触发器配置。

## 调用限制

| 项    | 值                             |
| ---- | ----------------------------- |
| 速率限制 | **1,000 次/分钟**；**50 次/秒** 每账户 |
| 权限   | 有效 `app_key`；管理操作要求调用者可管理目标规则 |

## 使用说明

* 可以创建个人规则，也可以创建当前 account 下任意团队规则；`team_id` 创建后不可修改。
* 列表可见性与 Session 列表对齐：Owner / 管理员可见全部；普通成员可见自己创建的规则和自己团队的规则。
* `http_post_token` 只在创建或轮换 token 的响应中返回，请立即保存。
* 如需由 On-call 故障触发，传入 `oncall_incident_trigger_enabled`、`oncall_incident_channel_ids` 与 `oncall_incident_severities`；匹配事件会以 `oncall_incident` 运行。


## OpenAPI

````yaml /api-reference/safari.openapi.zh.json post /safari/automation/rule/update
openapi: 3.1.0
info:
  title: Flashduty 开放 API
  description: >-
    Flashduty AI SRE 平台的公开 HTTP API —— 技能、MCP 服务器（连接器）、A2A 智能体与会话。所有接口均使用
    Flashduty 控制台签发的 `app_key` 查询参数进行认证。
  version: 1.0.0
servers:
  - url: https://api.flashcat.cloud
    description: Flashduty Open API
security:
  - AppKeyAuth: []
tags:
  - name: AI SRE/技能
  - name: AI SRE/MCP 服务器
  - name: AI SRE/A2A 智能体
  - name: AI SRE/会话
  - name: AI SRE/自动化
paths:
  /safari/automation/rule/update:
    post:
      tags:
        - AI SRE/自动化
      summary: 更新自动化规则
      description: 更新自动化规则的可变字段，包括 HTTP POST 与 On-call 故障触发器配置。
      operationId: automation-rule-write-update
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AutomationRuleUpdateRequest'
            example:
              rule_id: auto_7NnLzY2Qp8xS4kUaV3mR6b
              enabled: true
              cron_expr: 15 9 * * 1
              rotate_http_post_trigger_token: true
              oncall_incident_trigger_enabled: true
              oncall_incident_severities:
                - Critical
                - Warning
              oncall_incident_channel_ids:
                - 456
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/ResponseEnvelope'
                  - type: object
                    properties:
                      data:
                        $ref: '#/components/schemas/AutomationRuleItem'
              example:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                data:
                  rule_id: auto_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
                  prompt: Summarize last week's alert noise and escalation load.
                  environment_kind: ''
                  environment_id: ''
                  schedule_trigger_id: autotrg_6aKp3wT9mQ2xVc8bR1nY7z
                  schedule_trigger_enabled: true
                  http_post_trigger_id: autotrg_2bLq4xT8mP1sWd9cN3rF6y
                  http_post_trigger_url: >-
                    /safari/automation/triggers/autotrg_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: autotrg_9cVb2mN7qKs4dEa8T1rY5p
                  oncall_incident_trigger_enabled: true
                  oncall_incident_channel_ids:
                    - 456
                  oncall_incident_severities:
                    - Critical
                    - Warning
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/ServerError'
      security:
        - AppKeyAuth: []
components:
  schemas:
    AutomationRuleUpdateRequest:
      type: object
      description: 更新自动化规则。省略字段表示不修改。
      properties:
        rule_id:
          type: string
          description: 目标规则 ID。
        name:
          type: string
          maxLength: 255
          description: 新规则名称。
        team_id:
          type: integer
          format: int64
          minimum: 0
          description: 只允许传当前值；创建后 personal / team scope 不可修改。
        enabled:
          type: boolean
          description: 是否启用规则。
        cron_expr:
          type: string
          description: >-
            运行周期。支持 4 段 `hour day month weekday`，会补 `minute=0`；也支持 5 段 `minute
            hour day month weekday`。分钟必须是固定整数，秒级 6 段不支持。创建 API 当前要求该字段，即使只启用
            HTTP POST trigger，也要提供一个有效 cron 并把 `schedule_trigger_enabled` 设为
            false。
          example: 15 9 * * *
        schedule_trigger_enabled:
          type: boolean
          description: 是否启用 schedule trigger。
        prompt:
          type: string
          description: 新的任务提示词。
        environment_kind:
          type: string
          description: 运行环境类型。省略或空字符串表示自动选择。
          enum:
            - ''
            - cloud
            - byoc
        environment_id:
          type: string
          description: BYOC Runner ID。
        http_post_trigger_enabled:
          type: boolean
          description: 是否启用 HTTP POST trigger。不存在时设为 true 会创建。
        oncall_incident_trigger_enabled:
          type: boolean
          description: 是否启用 On-call 故障触发器。
        oncall_incident_channel_ids:
          type: array
          items:
            type: integer
            format: int64
            minimum: 1
          description: 监听的 On-call 集成 ID 列表；创建或启用该触发器时至少需要一个有效 ID。
        oncall_incident_severities:
          type: array
          items:
            type: string
            enum:
              - Critical
              - Warning
              - Info
          description: 监听的故障严重程度，支持 Critical、Warning 和 Info；创建或启用该触发器时至少需要一个值。
        rotate_http_post_trigger_token:
          type: boolean
          description: 是否轮换 HTTP POST trigger token。新 token 只会在本次响应中返回。
      required:
        - rule_id
    ResponseEnvelope:
      type: object
      description: >-
        Standard response envelope used by every Flashduty public API. On
        success `data` contains the endpoint-specific payload and `error` is
        absent. On failure `error` is present and `data` is absent. `request_id`
        is always present and is also mirrored in the `Flashcat-Request-Id`
        response header.
      properties:
        request_id:
          type: string
          description: >-
            Unique ID for this request. Mirrored in the Flashcat-Request-Id
            header. Include it when reporting issues.
          example: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
        error:
          $ref: '#/components/schemas/DutyError'
        data:
          description: Endpoint-specific payload. See each operation's 200 response schema.
      required:
        - request_id
    AutomationRuleItem:
      type: object
      description: 自动化规则。
      properties:
        rule_id:
          type: string
          description: 规则 ID。
        account_id:
          type: integer
          format: int64
          description: 账户 ID。
        team_id:
          type: integer
          format: int64
          description: 作用域团队 ID；0 表示个人规则。
        owner_id:
          type: integer
          format: int64
          description: 创建者 person ID。
        name:
          type: string
          description: 规则名称。
        enabled:
          type: boolean
          description: 规则是否启用。
        run_scope:
          type: string
          enum:
            - person
            - team
          description: 运行会话作用域。
        cron_expr:
          type: string
          description: 规范化后的 5 段 cron 表达式。
        prompt:
          type: string
          description: 任务提示词。
        environment_kind:
          type: string
          description: 运行环境类型。省略或空字符串表示自动选择。
          enum:
            - ''
            - cloud
            - byoc
        environment_id:
          type: string
          description: BYOC Runner ID。
        schedule_trigger_id:
          type: string
          description: Schedule trigger ID。
        schedule_trigger_enabled:
          type: boolean
          description: Schedule trigger 是否启用。
        http_post_trigger_id:
          type: string
          description: HTTP POST trigger ID。
        http_post_trigger_url:
          type: string
          description: HTTP POST 触发路径。
        http_post_trigger_enabled:
          type: boolean
          description: HTTP POST trigger 是否启用。
        oncall_incident_trigger_id:
          type: string
          description: On-call 故障触发器 ID。
        oncall_incident_trigger_enabled:
          type: boolean
          description: 是否启用 On-call 故障触发器。
        oncall_incident_channel_ids:
          type: array
          items:
            type: integer
            format: int64
            minimum: 1
          description: 监听的 On-call 集成 ID 列表；创建或启用该触发器时至少需要一个有效 ID。
        oncall_incident_severities:
          type: array
          items:
            type: string
            enum:
              - Critical
              - Warning
              - Info
          description: 监听的故障严重程度，支持 Critical、Warning 和 Info；创建或启用该触发器时至少需要一个值。
        http_post_token:
          type: string
          description: HTTP POST trigger token。只在创建或轮换 token 的响应中返回；请立即保存。
        can_edit:
          type: boolean
          description: 当前调用者是否可管理该规则。
        created_at:
          type: integer
          format: int64
          description: 创建时间，Unix 毫秒。
        updated_at:
          type: integer
          format: int64
          description: 更新时间，Unix 毫秒。
        schedule_next_fire_at_ms:
          type: integer
          format: int64
          description: 下一次计划触发时间，Unix 毫秒；0 表示暂无可用的下一次计划触发。
      required:
        - rule_id
        - account_id
        - team_id
        - owner_id
        - name
        - enabled
        - run_scope
        - cron_expr
        - prompt
        - environment_kind
        - environment_id
        - schedule_trigger_enabled
        - http_post_trigger_enabled
        - can_edit
        - created_at
        - updated_at
        - schedule_next_fire_at_ms
        - oncall_incident_trigger_enabled
    DutyError:
      type: object
      description: >-
        Error payload inside the response envelope. Present only on non-2xx
        responses.
      properties:
        code:
          $ref: '#/components/schemas/ErrorCode'
        message:
          type: string
          description: >-
            Human-readable error message, localized by the caller's
            Accept-Language. May contain field names, IDs, or other context from
            the failing request.
      required:
        - code
        - message
    ErrorResponse:
      type: object
      description: Response envelope for errors. `error` is required; `data` is absent.
      properties:
        request_id:
          type: string
          example: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
        error:
          $ref: '#/components/schemas/DutyError'
      required:
        - request_id
        - error
    ErrorCode:
      type: string
      description: >-
        Flashduty error code enum. Every failed API response sets `error.code`
        to one of these values. The value is a stable wire string — not a
        localized message and not a numeric status. HTTP status is
        informational.
      enum:
        - OK
        - InvalidParameter
        - BadRequest
        - InvalidContentType
        - ResourceNotFound
        - NoLicense
        - ReferenceExist
        - Unauthorized
        - BalanceNotEnough
        - AccessDenied
        - RouteNotFound
        - MethodNotAllowed
        - UndonedOrderExist
        - RequestLocked
        - EntityTooLarge
        - RequestTooFrequently
        - RequestVerifyRequired
        - DangerousOperation
        - InternalError
        - ServiceUnavailable
  responses:
    BadRequest:
      description: Invalid request — usually a missing or malformed parameter.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingParameter:
              summary: Missing required parameter
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: InvalidParameter
                  message: The specified parameter skill_id is not valid.
    Unauthorized:
      description: Missing or invalid app_key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            missingAppKey:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: Unauthorized
                  message: You are unauthorized.
    Forbidden:
      description: The app_key is valid but lacks permission for this operation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            accessDenied:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: AccessDenied
                  message: Access Denied.
    TooManyRequests:
      description: Rate limit hit. Either the global API limit or a per-account limit.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            rateLimited:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: RequestTooFrequently
                  message: Request too frequently.
    ServerError:
      description: Unexpected server-side error. Include the request_id when reporting.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          examples:
            internal:
              value:
                request_id: 01HK8XQE3Z7JM2NTFQ5YJ8P9R4
                error:
                  code: InternalError
                  message: >-
                    We encountered an internal error, and it has been reported.
                    Please try again later.
  securitySchemes:
    AppKeyAuth:
      type: apiKey
      in: query
      name: app_key
      description: >-
        App key issued from the Flashduty console. Required on every public API
        call. Keep it secret — it grants the same access as the owning account.

````