---
type: api
title: Update a rule
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v8/operation/operation-put-alerting-rule-id
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/v8/operation/operation-put-alerting-rule-id
products:
  - Kibana
---

# Update a rule

- Server: `https://{kibana_url}`

## Paths

- `PUT` `/api/alerting/rule/{id}`
- `PUT` `/s/{space_id}/api/alerting/rule/{id}`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana/v8/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/kibana/v8/authentication#basicauth)

#### Path Parameters

- `id` (string)
  The identifier for the rule.

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

## Request Body

`application/json`

- `actions` ([] object · default: []) — optional
  - `alerts_filter` (object) — optional
    - `query` (object) — optional
      - `dsl` (string) — optional
        A filter written in Elasticsearch Query Domain Specific Language (DSL).
      - `filters` ([] object) — required
        A filter written in Elasticsearch Query Domain Specific Language (DSL) as defined in the `kbn-es-query` package.
        - `$state` (object) — optional
          - `store` (enum) — required
            A filter can be either specific to an application context or applied globally.
            Values: `appState`, `globalState`
        - `meta` (map string to object) — required
        - `query` (map string to object) — optional
      - `kql` (string) — required
        A filter written in Kibana Query Language (KQL).
    - `timeframe` (object) — optional
      Defines a period that limits whether the action runs.
      - `days` ([] enum) — required
        Defines the days of the week that the action can run, represented as an array of numbers. For example, `1` represents Monday. An empty array is equivalent to specifying all the days of the week.
        Values: `1`, `2`, `3`, `4`, `5`, `6`, `7`
      - `hours` (object) — required
        Defines the range of time in a day that the action can run. If the `start` value is `00:00` and the `end` value is `24:00`, actions be generated all day.
        - `end` (string) — required
          The end of the time frame in 24-hour notation (`hh:mm`).
        - `start` (string) — required
          The start of the time frame in 24-hour notation (`hh:mm`).
      - `timezone` (string) — required
        The ISO time zone for the `hours` values. Values such as `UTC` and `UTC+1` also work but lack built-in daylight savings time support and are not recommended.
  - `frequency` (object) — optional
    - `notify_when` (enum) — required
      Indicates how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. NOTE: You cannot specify `notify_when` at both the rule and action level. The recommended method is to set it for each action. If you set it at the rule level then update the rule in Kibana, it is automatically changed to use action-specific values.
      Values: `onActionGroupChange`, `onActiveAlert`, `onThrottleInterval`
    - `summary` (boolean) — required
      Indicates whether the action is a summary.
    - `throttle` (string) — required — nullable
      The throttle interval, which defines how often an alert generates repeated actions. It is specified in seconds, minutes, hours, or days and is applicable only if `notify_when` is set to `onThrottleInterval`. NOTE: You cannot specify the throttle interval at both the rule and action level. The recommended method is to set it for each action. If you set it at the rule level then update the rule in Kibana, it is automatically changed to use action-specific values.
  - `group` (string) — optional
    The group name, which affects when the action runs (for example, when the threshold is met or when the alert is recovered). Each rule type has a list of valid action group names. If you don't need to group actions, set to `default`.
  - `id` (string) — required
    The identifier for the connector saved object.
  - `params` (map string to object · default: {}) — optional
    The parameters for the action, which are sent to the connector. The `params` are handled as Mustache templates and passed a default set of context.
  - `use_alert_data_for_template` (boolean) — optional
    Indicates whether to use alert data as a template.
  - `uuid` (string) — optional
    A universally unique identifier (UUID) for the action.
- `alert_delay` (object) — optional
  Indicates that an alert occurs only when the specified number of consecutive runs met the rule conditions.
  - `active` (number) — required
    The number of consecutive runs that must meet the rule conditions.
- `artifacts` (object) — optional
  - `dashboards` ([] object · max: 10) — optional
    - `id` (string) — required
  - `investigation_guide` (object) — optional
    - `blob` (string · max: 10000) — required
- `flapping` (object) — optional — nullable
  When flapping detection is turned on, alerts that switch quickly between active and recovered states are identified as “flapping” and notifications are reduced.
  - `look_back_window` (number · min: 2 · max: 20) — required
    The minimum number of runs in which the threshold must be met.
  - `status_change_threshold` (number · min: 2 · max: 20) — required
    The minimum number of times an alert must switch states in the look back window.
- `name` (string) — required
  The name of the rule. While this name does not have to be unique, a distinctive name can help you identify a rule.
- `notify_when` (enum) — optional — nullable
  Indicates how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. NOTE: You cannot specify `notify_when` at both the rule and action level. The recommended method is to set it for each action. If you set it at the rule level then update the rule in Kibana, it is automatically changed to use action-specific values.
  Values: `onActionGroupChange`, `onActiveAlert`, `onThrottleInterval`
- `params` (map string to object · default: {}) — optional
  The parameters for the rule.
- `schedule` (object) — required
  - `interval` (string) — required
    The interval is specified in seconds, minutes, hours, or days.
- `tags` ([] string · default: []) — optional
- `throttle` (string) — optional — nullable
  Use the `throttle` property in the action `frequency` object instead. The throttle interval, which defines how often an alert generates repeated actions. NOTE: You cannot specify the throttle interval at both the rule and action level. If you set it at the rule level then update the rule in Kibana, it is automatically changed to use action-specific values.

## Responses

#### `200`

Indicates a successful call.

`application/json`

- `actions` ([] object)
  - `alerts_filter` (object)
    Defines a period that limits whether the action runs.
    - `query` (object)
      - `dsl` (string)
        A filter written in Elasticsearch Query Domain Specific Language (DSL).
      - `filters` ([] object)
        A filter written in Elasticsearch Query Domain Specific Language (DSL) as defined in the `kbn-es-query` package.
        - `$state` (object)
          - `store` (enum)
            A filter can be either specific to an application context or applied globally.
            Values: `appState`, `globalState`
        - `meta` (map string to object)
        - `query` (map string to object)
      - `kql` (string)
        A filter written in Kibana Query Language (KQL).
    - `timeframe` (object)
      - `days` ([] enum)
        Defines the days of the week that the action can run, represented as an array of numbers. For example, `1` represents Monday. An empty array is equivalent to specifying all the days of the week.
        Values: `1`, `2`, `3`, `4`, `5`, `6`, `7`
      - `hours` (object)
        - `end` (string)
          The end of the time frame in 24-hour notation (`hh:mm`).
        - `start` (string)
          The start of the time frame in 24-hour notation (`hh:mm`).
      - `timezone` (string)
        The ISO time zone for the `hours` values. Values such as `UTC` and `UTC+1` also work but lack built-in daylight savings time support and are not recommended.
  - `connector_type_id` (string)
    The type of connector. This property appears in responses but cannot be set in requests.
  - `frequency` (object)
    - `notify_when` (enum)
      Indicates how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. NOTE: You cannot specify `notify_when` at both the rule and action level. The recommended method is to set it for each action. If you set it at the rule level then update the rule in Kibana, it is automatically changed to use action-specific values.
      Values: `onActionGroupChange`, `onActiveAlert`, `onThrottleInterval`
    - `summary` (boolean)
      Indicates whether the action is a summary.
    - `throttle` (string) — nullable
      The throttle interval, which defines how often an alert generates repeated actions. It is specified in seconds, minutes, hours, or days and is applicable only if 'notify_when' is set to 'onThrottleInterval'. NOTE: You cannot specify the throttle interval at both the rule and action level. The recommended method is to set it for each action. If you set it at the rule level then update the rule in Kibana, it is automatically changed to use action-specific values.
  - `group` (string)
    The group name, which affects when the action runs (for example, when the threshold is met or when the alert is recovered). Each rule type has a list of valid action group names. If you don't need to group actions, set to `default`.
  - `id` (string)
    The identifier for the connector saved object.
  - `params` (map string to object)
    The parameters for the action, which are sent to the connector. The `params` are handled as Mustache templates and passed a default set of context.
  - `use_alert_data_for_template` (boolean)
    Indicates whether to use alert data as a template.
  - `uuid` (string)
    A universally unique identifier (UUID) for the action.
- `active_snoozes` ([] string)
- `alert_delay` (object)
  Indicates that an alert occurs only when the specified number of consecutive runs met the rule conditions.
  - `active` (number)
    The number of consecutive runs that must meet the rule conditions.
- `api_key_created_by_user` (boolean) — nullable
  Indicates whether the API key that is associated with the rule was created by the user.
- `api_key_owner` (string) — nullable
  The owner of the API key that is associated with the rule and used to run background tasks.
- `artifacts` (object)
  - `dashboards` ([] object)
    - `id` (string)
  - `investigation_guide` (object)
    - `blob` (string)
      User-created content that describes alert causes and remdiation.
- `consumer` (string)
  The name of the application or feature that owns the rule. For example: `alerts`, `apm`, `discover`, `infrastructure`, `logs`, `metrics`, `ml`, `monitoring`, `securitySolution`, `siem`, `stackAlerts`, or `uptime`.
- `created_at` (string)
  The date and time that the rule was created.
- `created_by` (string) — nullable
  The identifier for the user that created the rule.
- `enabled` (boolean)
  Indicates whether you want to run the rule on an interval basis after it is created.
- `execution_status` (object)
  - `error` (object)
    - `message` (string)
      Error message.
    - `reason` (enum)
      Reason for error.
      Values: `read`, `decrypt`, `execute`, `unknown`, `license`, `timeout`, `disabled`, `validate`
  - `last_duration` (number)
    Duration of last execution of the rule.
  - `last_execution_date` (string)
    The date and time when rule was executed last.
  - `status` (enum)
    Status of rule execution.
    Values: `ok`, `active`, `error`, `warning`, `pending`, `unknown`
  - `warning` (object)
    - `message` (string)
      Warning message.
    - `reason` (enum)
      Reason for warning.
      Values: `maxExecutableActions`, `maxAlerts`, `maxQueuedActions`, `ruleExecution`
- `flapping` (object) — nullable
  When flapping detection is turned on, alerts that switch quickly between active and recovered states are identified as “flapping” and notifications are reduced.
  - `look_back_window` (number · min: 2 · max: 20)
    The minimum number of runs in which the threshold must be met.
  - `status_change_threshold` (number · min: 2 · max: 20)
    The minimum number of times an alert must switch states in the look back window.
- `id` (string)
  The identifier for the rule.
- `is_snoozed_until` (string) — nullable
  The date when the rule will no longer be snoozed.
- `last_run` (object) — nullable
  - `alerts_count` (object)
    - `active` (number) — nullable
      Number of active alerts during last run.
    - `ignored` (number) — nullable
      Number of ignored alerts during last run.
    - `new` (number) — nullable
      Number of new alerts during last run.
    - `recovered` (number) — nullable
      Number of recovered alerts during last run.
  - `outcome` (enum)
    Outcome of last run of the rule. Value could be succeeded, warning or failed.
    Values: `succeeded`, `warning`, `failed`
  - `outcome_msg` ([] string) — nullable
  - `outcome_order` (number)
    Order of the outcome.
  - `warning` (enum) — nullable
    Warning of last rule execution.
    Values: `read`, `decrypt`, `execute`, `unknown`, `license`, `timeout`, `disabled`, `validate`, `maxExecutableActions`, `maxAlerts`, `maxQueuedActions`, `ruleExecution`
- `mapped_params` (map string to object)
- `monitoring` (object)
  Monitoring details of the rule.
  - `run` (object)
    Rule run details.
    - `calculated_metrics` (object)
      Calculation of different percentiles and success ratio.
      - `p50` (number)
      - `p95` (number)
      - `p99` (number)
      - `success_ratio` (number)
    - `history` ([] object)
      History of the rule run.
      - `duration` (number)
        Duration of the rule run.
      - `outcome` (enum)
        Outcome of last run of the rule. Value could be succeeded, warning or failed.
        Values: `succeeded`, `warning`, `failed`
      - `success` (boolean)
        Indicates whether the rule run was successful.
      - `timestamp` (number)
        Time of rule run.
    - `last_run` (object)
      - `metrics` (object)
        - `duration` (number)
          Duration of most recent rule run.
        - `gap_duration_s` (number) — nullable
          Duration in seconds of rule run gap.
        - `gap_range` (object) — nullable
          - `gte` (string)
            End of the gap range.
          - `lte` (string)
            Start of the gap range.
        - `total_alerts_created` (number) — nullable
          Total number of alerts created during last rule run.
        - `total_alerts_detected` (number) — nullable
          Total number of alerts detected during last rule run.
        - `total_indexing_duration_ms` (number) — nullable
          Total time spent indexing documents during last rule run in milliseconds.
        - `total_search_duration_ms` (number) — nullable
          Total time spent performing Elasticsearch searches as measured by Kibana; includes network latency and time spent serializing or deserializing the request and response.
      - `timestamp` (string)
        Time of the most recent rule run.
- `mute_all` (boolean)
  Indicates whether all alerts are muted.
- `muted_alert_ids` ([] string)
- `name` (string)
   The name of the rule.
- `next_run` (string) — nullable
  Date and time of the next run of the rule.
- `notify_when` (enum) — nullable
  Indicates how often alerts generate actions. Valid values include: `onActionGroupChange`: Actions run when the alert status changes; `onActiveAlert`: Actions run when the alert becomes active and at each check interval while the rule conditions are met; `onThrottleInterval`: Actions run when the alert becomes active and at the interval specified in the throttle property while the rule conditions are met. NOTE: You cannot specify `notify_when` at both the rule and action level. The recommended method is to set it for each action. If you set it at the rule level then update the rule in Kibana, it is automatically changed to use action-specific values.
  Values: `onActionGroupChange`, `onActiveAlert`, `onThrottleInterval`
- `params` (map string to object)
  The parameters for the rule.
- `revision` (number)
  The rule revision number.
- `rule_type_id` (string)
  The rule type identifier.
- `running` (boolean) — nullable
  Indicates whether the rule is running.
- `schedule` (object)
  - `interval` (string)
    The interval is specified in seconds, minutes, hours, or days.
- `scheduled_task_id` (string)
  Identifier of the scheduled task.
- `snooze_schedule` ([] object)
  - `duration` (number)
    Duration of the rule snooze schedule.
  - `id` (string)
    Identifier of the rule snooze schedule.
  - `rRule` (object)
    - `byhour` ([] number) — nullable
    - `byminute` ([] number) — nullable
    - `bymonth` ([] number) — nullable
    - `bymonthday` ([] number) — nullable
    - `bysecond` ([] number) — nullable
    - `bysetpos` ([] number) — nullable
    - `byweekday` ([] number | string) — nullable
    - `byweekno` ([] number) — nullable
    - `byyearday` ([] number) — nullable
    - `count` (number)
      Number of times the rule should recur until it stops.
    - `dtstart` (string)
      Rule start date in Coordinated Universal Time (UTC).
    - `freq` (enum)
      Indicates frequency of the rule. Options are YEARLY, MONTHLY, WEEKLY, DAILY.
      Values: `0`, `1`, `2`, `3`, `4`, `5`, `6`
    - `interval` (number)
      Indicates the interval of frequency. For example, 1 and YEARLY is every 1 year, 2 and WEEKLY is every 2 weeks.
    - `tzid` (string)
      Indicates timezone abbreviation.
    - `until` (string)
      Recur the rule until this date.
    - `wkst` (enum)
      Indicates the start of week, defaults to Monday.
      Values: `MO`, `TU`, `WE`, `TH`, `FR`, `SA`, `SU`
  - `skipRecurrences` ([] string)
- `tags` ([] string)
- `throttle` (string) — nullable — deprecated
  Deprecated in 8.13.0. Use the `throttle` property in the action `frequency` object instead. The throttle interval, which defines how often an alert generates repeated actions. NOTE: You cannot specify the throttle interval at both the rule and action level. If you set it at the rule level then update the rule in Kibana, it is automatically changed to use action-specific values.
- `updated_at` (string)
  The date and time that the rule was updated most recently.
- `updated_by` (string) — nullable
  The identifier for the user that updated this rule most recently.
- `view_in_app_relative_url` (string) — nullable
  Relative URL to view rule in the app.
#### `400`

Indicates an invalid schema or parameters.

#### `403`

Indicates that this call is forbidden.

#### `404`

Indicates a rule with the given ID does not exist.

#### `409`

Indicates that the rule has already been updated by another user.

## Code Examples

#### Console

```console
PUT /api/alerting/rule/{id}
{
  "actions": [
    {
      "frequency": {
        "summary": false,
        "notify_when": "onActionGroupChange"
      },
      "group": "threshold met",
      "id": "96b668d0-a1b6-11ed-afdf-d39a49596974",
      "params": {
        "level": "info",
        "message": "Rule {{rule.name}} is active for group {{context.group}}:\n\n- Value: {{context.value}}\n- Conditions Met: {{context.conditions}} over {{rule.params.timeWindowSize}}{{rule.params.timeWindowUnit}}\n- Timestamp: {{context.date}}"
      }
    }
  ],
  "params": {
    "aggField": "sheet.version",
    "aggType": "avg",
    "index": [
      ".updated-index"
    ],
    "groupBy": "top",
    "termField": "name.keyword",
    "termSize": 6,
    "threshold": [
      1000
    ],
    "thresholdComparator": "\u003E",
    "timeField": "@timestamp",
    "timeWindowSize": 5,
    "timeWindowUnit": "m"
  },
  "name": "new name",
  "schedule": {
    "interval": "1m"
  },
  "tags": []
}
```

#### curl

```curl
curl -X PUT "https://{kibana_url}/api/alerting/rule/{id}" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
  "actions": [
    {
      "frequency": {
        "summary": false,
        "notify_when": "onActionGroupChange"
      },
      "group": "threshold met",
      "id": "96b668d0-a1b6-11ed-afdf-d39a49596974",
      "params": {
        "level": "info",
        "message": "Rule {{rule.name}} is active for group {{context.group}}:\n\n- Value: {{context.value}}\n- Conditions Met: {{context.conditions}} over {{rule.params.timeWindowSize}}{{rule.params.timeWindowUnit}}\n- Timestamp: {{context.date}}"
      }
    }
  ],
  "params": {
    "aggField": "sheet.version",
    "aggType": "avg",
    "index": [
      ".updated-index"
    ],
    "groupBy": "top",
    "termField": "name.keyword",
    "termSize": 6,
    "threshold": [
      1000
    ],
    "thresholdComparator": "\u003E",
    "timeField": "@timestamp",
    "timeWindowSize": 5,
    "timeWindowUnit": "m"
  },
  "name": "new name",
  "schedule": {
    "interval": "1m"
  },
  "tags": []
}'
```

## Response Examples

#### Index threshold rule

The response for successfully updating an index threshold rule.

```json
{
  "id": "ac4e6b90-6be7-11eb-ba0d-9b1c1f912d74",
  "consumer": "alerts",
  "tags": [],
  "name": "new name",
  "enabled": true,
  "throttle": "null",
  "revision": 1,
  "running": false,
  "schedule": {
    "interval": "1m"
  },
  "params": {
    "index": [
      ".updated-index"
    ],
    "timeField": "@timestamp",
    "groupBy": "top",
    "aggType": "avg",
    "timeWindowSize": 5,
    "timeWindowUnit": "m",
    "thresholdComparator": "\u003E",
    "threshold": [
      1000
    ],
    "aggField": "sheet.version",
    "termField": "name.keyword",
    "termSize": 6
  },
  "api_key_owner": "elastic",
  "created_by": "elastic",
  "updated_by": "elastic",
  "rule_type_id": ".index-threshold",
  "scheduled_task_id": "4c5eda00-e74f-11ec-b72f-5b18752ff9ea",
  "created_at": "2024-03-26T23:13:20.985Z",
  "updated_at": "2024-03-26T23:22:59.949Z",
  "mute_all": false,
  "muted_alert_ids": [],
  "execution_status": {
    "status": "ok",
    "last_execution_date": "2024-03-26T23:22:51.390Z",
    "last_duration": 52
  },
  "actions": [
    {
      "group": "threshold met",
      "params": {
        "level": "info",
        "message": "Rule {{rule.name}} is active for group {{context.group}}:\n\n- Value: {{context.value}}\n- Conditions Met: {{context.conditions}} over {{rule.params.timeWindowSize}}{{rule.params.timeWindowUnit}}\n- Timestamp: {{context.date}"
      },
      "id": "96b668d0-a1b6-11ed-afdf-d39a49596974",
      "uuid": "07aef2a0-9eed-4ef9-94ec-39ba58eb609d",
      "connector_type_id": ".server-log",
      "frequency": {
        "summary": false,
        "throttle": "null",
        "notify_when": "onActionGroupChange"
      }
    }
  ],
  "last_run": {
    "alerts_count": {
      "new": 0,
      "ignored": 0,
      "recovered": 0,
      "active": 0
    },
    "outcome_msg": "null",
    "warning": "null",
    "outcome": "succeeded"
  },
  "next_run": "2024-03-26T23:23:51.316Z",
  "api_key_created_by_user": false
}
```

