跳至主要内容

Create alert policy

POST 

/api/v1/orgs/{orgId}/alert-policies

Create a new alert policy definition. New policies always start disabled; call the enable/disable action afterwards to activate evaluation. Device/data-stream bindings are managed separately via the data-streams sub-resource, not part of this payload.

Request Body

  • policyName (string, required): Policy name. Must be unique within the org (among non-deleted policies). Ex: WaterLevel alert policy.
  • description (string, optional): Policy description. Max length: 500.
  • alertLevel (string, required): Trigger threshold expression, evaluated against the incoming data stream value. Ex: >=70.
  • alertResetLevel (string, required): Reset/release threshold expression. Ex: <65.
  • delay (integer, optional, default: 0): Debounce delay in seconds. The condition must hold continuously for this many seconds before an alert is actually fired or released; 0 disables debouncing (fires/releases almost immediately). Must be non-negative.
  • notification (object, optional): Notification configuration for this policy. Omit to leave the policy without any notification target (no message is sent when it fires).
    • channelIds (string[], required): Existing channel IDs to notify. Ex: channel_3fa85f64-5717-4562-b3fc-2c963f66afa6. Every ID must belong to an existing channel in this org.
    • recipients (array, required): Recipients for the notification. Each item: name (string, optional), target (string, required), type (string, required — to/cc/bcc).
    • templateId (string, optional): Existing template ID to render. Ex: tmpl_7fa85f64-5717-4562-b3fc-2c963f66afa6. Use together with variables; mutually exclusive with subject/content (providing both results in 400).
    • variables (object, optional): Key/value substitutions used when rendering the template. Ex: {"threshold": "70"}. Only meaningful together with templateId.
    • subject (string, optional): Literal subject line, used instead of a template. Mutually exclusive with templateId/variables.
    • content (string, optional): Literal message content, used instead of a template. Mutually exclusive with templateId/variables.

Responses

  • 201 Created: Alert policy created successfully.
  • 400 Bad Request: Validation error (missing required field, invalid range, or templateId+subject/content both provided).
  • 404 Not Found: A channelIds entry or templateId does not exist in this org.
  • 409 Conflict: An alert policy with the same policyName already exists in this org.

Request

Responses

Created