# Create

Launch stage: GA

`POST /api/2.0/sql/alerts`

Creates an alert.

API scopes: sql

## Request body

- `alert` (object, optional)
  - `id` (string, optional)
    UUID identifying the alert.
    Example: `fe25e731-92f2-4838-9fb2-1ca364320a3d`
  - `display_name` (string, optional)
    The display name of the alert.
    Example: `Example alert`
  - `query_id` (string, optional)
    UUID of the query attached to the alert.
    Example: `dee5cca8-1c79-4b5e-a711-e7f9d241bdf6`
  - `state` (string, optional)
    Current state of the alert's trigger status. This field is set to UNKNOWN if the alert has not yet been evaluated or ran into an error during the last evaluation.
    Possible values: `UNKNOWN`, `OK`, `TRIGGERED`
    Example: `UNKNOWN`
  - `seconds_to_retrigger` (int32, optional)
    Number of seconds an alert must wait after being triggered to rearm itself. After rearming, it can be triggered again. If 0 or not specified, the alert will not be triggered again.
    Example: `0`
  - `lifecycle_state` (string, optional)
    The workspace state of the alert. Used for tracking trashed status.
    Possible values: `ACTIVE`, `TRASHED`
    Example: `ACTIVE`
  - `trigger_time` (string, optional)
    Timestamp when the alert was last triggered, if the alert has been triggered before.
  - `custom_body` (string, optional)
    Custom body of alert notification, if it exists. See [here](https://docs.databricks.com/sql/user/alerts/index.html) for custom templating instructions.
    Example: `custom body`
  - `custom_subject` (string, optional)
    Custom subject of alert notification, if it exists. This can include email subject entries and Slack notification headers, for example. See [here](https://docs.databricks.com/sql/user/alerts/index.html) for custom templating instructions.
    Example: `custom subject`
  - `condition` (object, optional)
    Trigger conditions of the alert.
    - `op` (string, optional)
      Operator used for comparison in alert evaluation.
      Possible values: `GREATER_THAN`, `GREATER_THAN_OR_EQUAL`, `LESS_THAN`, `LESS_THAN_OR_EQUAL`, `EQUAL`, `NOT_EQUAL`, `IS_NULL`
    - `operand` (object, optional)
      Name of the column from the query result to use for comparison in alert evaluation.
      - `value` (object, required)
      - `column` (object, required)
    - `threshold` (object, optional)
      Threshold value used for comparison in alert evaluation.
      - `value` (object, required)
      - `column` (object, required)
    - `empty_result_state` (string, optional)
      Alert state if result is empty.
      Possible values: `UNKNOWN`, `OK`, `TRIGGERED`
  - `owner_user_name` (string, optional)
    The owner's username. This field is set to "Unavailable" if the user has been deleted.
    Example: `user@acme.com`
  - `parent_path` (string, optional)
    The workspace path of the folder containing the alert.
    Example: `/Users/user@acme.com`
  - `create_time` (string, optional)
    The timestamp indicating when the alert was created.
  - `update_time` (string, optional)
    The timestamp indicating when the alert was updated.
  - `notify_on_ok` (boolean, optional)
    Whether to notify alert subscribers when alert returns back to normal.
- `auto_resolve_display_name` (boolean, optional)
  If true, automatically resolve alert display name conflicts. Otherwise, fail the request if the alert's display name conflicts with an existing alert's display name.
  Default: `true`

## Returns

Returns the Alert object.

## Request

```json
{
  "alert": {
    "condition": {
      "op": "GREATER_THAN",
      "operand": {
        "column": {
          "name": "foo"
        }
      },
      "threshold": {
        "value": {
          "double_value": 1
        }
      }
    },
    "display_name": "Test alert",
    "parent_path": "/Workspace/Users/user.name@acme.com",
    "query_id": "dee5cca8-1c79-4b5e-a71m1-e7f9d241bdf6",
    "seconds_to_retrigger": 0
  }
}
```

## Response

```json
{
  "condition": {
    "op": "GREATER_THAN",
    "operand": {
      "column": {
        "name": "foo"
      }
    },
    "threshold": {
      "value": {
        "double_value": 1
      }
    }
  },
  "create_time": "2019-08-24T14:15:22Z",
  "display_name": "Test alert",
  "id": "fe25e731-92f2-4838-9fb2-1ca364320a3d",
  "lifecycle_state": "ACTIVE",
  "owner_user_name": "user.name@acme.com",
  "parent_path": "/Workspace/Users/user.name@acme.com",
  "query_id": "dee5cca8-1c79-4b5e-a711-e7f9d241bdf6",
  "seconds_to_retrigger": 0,
  "state": "OK",
  "update_time": "2019-08-24T14:15:22Z"
}
```

