# Alarm policies

Alarm policies: who and which channels an alarm notifies.

Its operations need the scopes `policies.edit`, `policies.view` or `policies.delete`.

**Endpoints**

- `POST/v1/alarm-policies`
- `PUT/v1/alarm-policies/{policy_uuid}`
- `GET/v1/alarm-policies/{policy_uuid}`
- `GET/v1/alarm-policies`
- `DELETE/v1/alarm-policies/{policy_uuid}`

## The Alarm policy object

### Attributes

- `uuid` (string): The policy’s uuid.
- `name` (string): The policy’s name.
- `default` (boolean): Whether this is the organisation’s default policy, which cannot be deleted.
- `all_users` (boolean): Whether every user of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_channels` (boolean): Whether every alarm channel of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_groups` (boolean): Whether every contact group of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_users_channels` (array of strings): The ways every user is reached when `all_users` is on for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_groups_channels` (array of strings): The ways every group member is reached when `all_groups` is on for a warning incident (and a critical one while `critical_uses_warning` is true).
- `notifies` (array of objects): Who the policy notifies for a warning incident, and for a critical one while `critical_uses_warning` is true.
  - `target_type` (string): What the target is: `user`, `destination` (an alarm channel) or `contact_group`.
  - `target_uuid` (string or null): The target’s uuid; null if the record is gone.
  - `label` (string or null): The target’s name; null if the record is gone.
  - `channels` (array of strings): For a user, the ways the user is reached; for a destination, its type; empty for a group.
- `critical_uses_warning` (boolean): Whether critical incidents use the same routing as warning ones. While true, `critical` is null.
- `critical` (object or null): The routing for critical incidents, while `critical_uses_warning` is false.
  - `all_users` (boolean): Whether every user of the organisation is notified for a critical incident.
  - `all_channels` (boolean): Whether every alarm channel of the organisation is notified for a critical incident.
  - `all_groups` (boolean): Whether every contact group of the organisation is notified for a critical incident.
  - `all_users_channels` (array of strings): The ways every user is reached for a critical incident when `critical.all_users` is on.
  - `all_groups_channels` (array of strings): The ways every group member is reached for a critical incident when `critical.all_groups` is on.
  - `notifies` (array of objects): Who the policy notifies for a critical incident besides its `critical.all_…` switches.
    - `target_type` (string): What the target is: `user`, `destination` (an alarm channel) or `contact_group`.
    - `target_uuid` (string or null): The target’s uuid; null if the record is gone.
    - `label` (string or null): The target’s name; null if the record is gone.
    - `channels` (array of strings): For a user, the ways the user is reached; for a destination, its type; empty for a group.

**The Alarm policy object**

```json
{
  "uuid": "75666699-b77d-4631-b576-041e8102a55b",
  "name": "example",
  "default": true,
  "all_users": true,
  "all_channels": true,
  "all_groups": true,
  "all_users_channels": [
    "example"
  ],
  "all_groups_channels": [
    "example"
  ],
  "notifies": [
    {
      "target_type": "example",
      "target_uuid": "98531987-06b0-4d73-932a-191917e6ec57",
      "label": "example",
      "channels": [
        "example"
      ]
    }
  ],
  "critical_uses_warning": true,
  "critical": {
    "all_users": true,
    "all_channels": true,
    "all_groups": true,
    "all_users_channels": [
      "example"
    ],
    "all_groups_channels": [
      "example"
    ],
    "notifies": [
      {
        "target_type": "example",
        "target_uuid": "98531987-06b0-4d73-932a-191917e6ec57",
        "label": "example",
        "channels": [
          "example"
        ]
      }
    ]
  }
}
```

## Create an alarm policy

POST/v1/alarm-policies

Creates an alarm policy from a name and who it notifies: every user, every channel or every contact group by a switch, and individual users, alarm channels and contact groups in `notifies`. That is who a warning incident notifies, and a critical one too unless a `critical` object gives the critical incidents their own route (or `critical_uses_warning` is false, which starts it as a copy of the warning route).

Needs the scope `policies.edit`.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same request within 24 hours returns the first answer without running again (the response carries `Idempotent-Replayed: true`); the same key on a different request is refused 422 `invalid_request`.

### Body parameters

- `name` (string, required): The policy’s name, up to 255 characters.
- `all_users` (boolean or null): Whether every user of the organisation is notified, by the channels of `all_users_channels`, for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_channels` (boolean or null): Whether every alarm channel of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_groups` (boolean or null): Whether every contact group of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_users_channels` (array of strings or null): The ways every user is reached when `all_users` is on for a warning incident (and a critical one while `critical_uses_warning` is true): `email`, `sms`, `whatsapp`. Values:`email``sms``whatsapp`(an open set: new values may be added)
- `all_groups_channels` (array of strings or null): The ways every group member is reached when `all_groups` is on for a warning incident (and a critical one while `critical_uses_warning` is true): `email`, `sms`, `whatsapp`. Values:`email``sms``whatsapp`(an open set: new values may be added)
- `notifies` (array of objects or null): Who the policy notifies for a warning incident (and a critical one while `critical_uses_warning` is true) besides its `all_…` switches, a full replacement of the saved ones: each a user, an alarm channel (`destination`) or a contact group. A kind whose `all_…` switch is on needs none.
  - `target_type` (string): What the target is: `user`, `destination` (an alarm channel) or `contact_group`. Values:`user``destination``contact_group`(an open set: new values may be added)
  - `target_uuid` (string (uuid)): The target’s uuid, in this organisation.
  - `channels` (array of strings or null): For a user target, the ways the user is reached: `email`, `sms`, `whatsapp`; email when none is given. Values:`email``sms``whatsapp`(an open set: new values may be added)
- `critical_uses_warning` (boolean or null): Whether critical incidents use the same routing as warning ones. While true, `critical` is null.
- `critical` (object): The routing for critical incidents, while `critical_uses_warning` is false.
  - `all_users` (boolean or null): Whether every user of the organisation is notified for a critical incident, by the channels of `critical.all_users_channels`.
  - `all_channels` (boolean or null): Whether every alarm channel of the organisation is notified for a critical incident.
  - `all_groups` (boolean or null): Whether every contact group of the organisation is notified for a critical incident.
  - `all_users_channels` (array of strings or null): The ways every user is reached for a critical incident when `critical.all_users` is on: `email`, `sms`, `whatsapp`. Values:`email``sms``whatsapp`(an open set: new values may be added)
  - `all_groups_channels` (array of strings or null): The ways every group member is reached for a critical incident when `critical.all_groups` is on: `email`, `sms`, `whatsapp`. Values:`email``sms``whatsapp`(an open set: new values may be added)
  - `notifies` (array of objects or null): Who the policy notifies for a critical incident besides its `critical.all_…` switches, a full replacement of the saved ones: each a user, an alarm channel (`destination`) or a contact group.
    - `target_type` (string): What the target is: `user`, `destination` (an alarm channel) or `contact_group`. Values:`user``destination``contact_group`(an open set: new values may be added)
    - `target_uuid` (string (uuid)): The target’s uuid, in this organisation.
    - `channels` (array of strings or null): For a user target, the ways the user is reached: `email`, `sms`, `whatsapp`; email when none is given. Values:`email``sms``whatsapp`(an open set: new values may be added)

### Returns

`201 Created`:

The created alarm policy.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**POST /v1/alarm-policies**

curl:

```bash
curl -X POST https://rest.watchtower15.com/v1/alarm-policies \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "name": "example"
  }'
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$alarmPolicy = $wt15->alarmPolicies->create(['name' => 'example']);
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.alarmPolicies.create({ name: 'example' });
```

Python:

```python
client = Client.from_environment()

result = client.alarm_policies.create(name='example')
```

**Response (201 Created)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "name": "example",
    "default": true,
    "all_users": true,
    "all_channels": true,
    "all_groups": true,
    "all_users_channels": [
      "example"
    ],
    "all_groups_channels": [
      "example"
    ],
    "notifies": [
      {
        "target_type": "example",
        "target_uuid": "98531987-06b0-4d73-932a-191917e6ec57",
        "label": "example",
        "channels": [
          "example"
        ]
      }
    ],
    "critical_uses_warning": true,
    "critical": {
      "all_users": true,
      "all_channels": true,
      "all_groups": true,
      "all_users_channels": [
        "example"
      ],
      "all_groups_channels": [
        "example"
      ],
      "notifies": [
        {
          "target_type": "example",
          "target_uuid": "98531987-06b0-4d73-932a-191917e6ec57",
          "label": "example",
          "channels": [
            "example"
          ]
        }
      ]
    }
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the policies.edit scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid; `errors` names the parameters.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Update an alarm policy

PUT/v1/alarm-policies/{policy\_uuid}

Changes the fields sent. What is not sent keeps its value. `notifies`, when sent, replaces the list of who the policy notifies: send the whole list, including the ones to keep. A `critical` object, when sent, replaces the whole Critical route; `critical_uses_warning: true` clears it.

Needs the scope `policies.edit`.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same request within 24 hours returns the first answer without running again (the response carries `Idempotent-Replayed: true`); the same key on a different request is refused 422 `invalid_request`.

### Path parameters

- `policy_uuid` (string (uuid), required): The uuid of the alarm policy in the path.

### Body parameters

- `name` (string or null): The policy’s name, up to 255 characters.
- `all_users` (boolean or null): Whether every user of the organisation is notified, by the channels of `all_users_channels`, for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_channels` (boolean or null): Whether every alarm channel of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_groups` (boolean or null): Whether every contact group of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_users_channels` (array of strings or null): The ways every user is reached when `all_users` is on for a warning incident (and a critical one while `critical_uses_warning` is true): `email`, `sms`, `whatsapp`. Values:`email``sms``whatsapp`(an open set: new values may be added)
- `all_groups_channels` (array of strings or null): The ways every group member is reached when `all_groups` is on for a warning incident (and a critical one while `critical_uses_warning` is true): `email`, `sms`, `whatsapp`. Values:`email``sms``whatsapp`(an open set: new values may be added)
- `notifies` (array of objects or null): Who the policy notifies for a warning incident (and a critical one while `critical_uses_warning` is true) besides its `all_…` switches, a full replacement of the saved ones: each a user, an alarm channel (`destination`) or a contact group. A kind whose `all_…` switch is on needs none.
  - `target_type` (string): What the target is: `user`, `destination` (an alarm channel) or `contact_group`. Values:`user``destination``contact_group`(an open set: new values may be added)
  - `target_uuid` (string (uuid)): The target’s uuid, in this organisation.
  - `channels` (array of strings or null): For a user target, the ways the user is reached: `email`, `sms`, `whatsapp`; email when none is given. Values:`email``sms``whatsapp`(an open set: new values may be added)
- `critical_uses_warning` (boolean or null): Whether critical incidents use the same routing as warning ones. While true, `critical` is null.
- `critical` (object): The routing for critical incidents, while `critical_uses_warning` is false.
  - `all_users` (boolean or null): Whether every user of the organisation is notified for a critical incident, by the channels of `critical.all_users_channels`.
  - `all_channels` (boolean or null): Whether every alarm channel of the organisation is notified for a critical incident.
  - `all_groups` (boolean or null): Whether every contact group of the organisation is notified for a critical incident.
  - `all_users_channels` (array of strings or null): The ways every user is reached for a critical incident when `critical.all_users` is on: `email`, `sms`, `whatsapp`. Values:`email``sms``whatsapp`(an open set: new values may be added)
  - `all_groups_channels` (array of strings or null): The ways every group member is reached for a critical incident when `critical.all_groups` is on: `email`, `sms`, `whatsapp`. Values:`email``sms``whatsapp`(an open set: new values may be added)
  - `notifies` (array of objects or null): Who the policy notifies for a critical incident besides its `critical.all_…` switches, a full replacement of the saved ones: each a user, an alarm channel (`destination`) or a contact group.
    - `target_type` (string): What the target is: `user`, `destination` (an alarm channel) or `contact_group`. Values:`user``destination``contact_group`(an open set: new values may be added)
    - `target_uuid` (string (uuid)): The target’s uuid, in this organisation.
    - `channels` (array of strings or null): For a user target, the ways the user is reached: `email`, `sms`, `whatsapp`; email when none is given. Values:`email``sms``whatsapp`(an open set: new values may be added)

### Returns

`200 OK`:

The alarm policy after the update.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**PUT /v1/alarm-policies/{policy_uuid}**

curl:

```bash
curl -X PUT https://rest.watchtower15.com/v1/alarm-policies/bef980be-2d82-440c-ab94-76d22f17bf41 \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$alarmPolicy = $wt15->alarmPolicies->update('bef980be-2d82-440c-ab94-76d22f17bf41');
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.alarmPolicies.update('bef980be-2d82-440c-ab94-76d22f17bf41');
```

Python:

```python
client = Client.from_environment()

result = client.alarm_policies.update('bef980be-2d82-440c-ab94-76d22f17bf41')
```

**Response (200 OK)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "name": "example",
    "default": true,
    "all_users": true,
    "all_channels": true,
    "all_groups": true,
    "all_users_channels": [
      "example"
    ],
    "all_groups_channels": [
      "example"
    ],
    "notifies": [
      {
        "target_type": "example",
        "target_uuid": "98531987-06b0-4d73-932a-191917e6ec57",
        "label": "example",
        "channels": [
          "example"
        ]
      }
    ],
    "critical_uses_warning": true,
    "critical": {
      "all_users": true,
      "all_channels": true,
      "all_groups": true,
      "all_users_channels": [
        "example"
      ],
      "all_groups_channels": [
        "example"
      ],
      "notifies": [
        {
          "target_type": "example",
          "target_uuid": "98531987-06b0-4d73-932a-191917e6ec57",
          "label": "example",
          "channels": [
            "example"
          ]
        }
      ]
    }
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the policies.edit scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid; `errors` names the parameters.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Get an alarm policy

GET/v1/alarm-policies/{policy\_uuid}

Returns one alarm policy: who and which channels an alarm that uses it notifies, with its targets.

Needs the scope `policies.view`.

### Path parameters

- `policy_uuid` (string (uuid), required): The uuid of the alarm policy in the path.

### Returns

`200 OK`:

The alarm policy.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/alarm-policies/{policy_uuid}**

curl:

```bash
curl https://rest.watchtower15.com/v1/alarm-policies/bef980be-2d82-440c-ab94-76d22f17bf41 \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$alarmPolicy = $wt15->alarmPolicies->view('bef980be-2d82-440c-ab94-76d22f17bf41');
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.alarmPolicies.view('bef980be-2d82-440c-ab94-76d22f17bf41');
```

Python:

```python
client = Client.from_environment()

result = client.alarm_policies.view('bef980be-2d82-440c-ab94-76d22f17bf41')
```

**Response (200 OK)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "name": "example",
    "default": true,
    "all_users": true,
    "all_channels": true,
    "all_groups": true,
    "all_users_channels": [
      "example"
    ],
    "all_groups_channels": [
      "example"
    ],
    "notifies": [
      {
        "target_type": "example",
        "target_uuid": "98531987-06b0-4d73-932a-191917e6ec57",
        "label": "example",
        "channels": [
          "example"
        ]
      }
    ],
    "critical_uses_warning": true,
    "critical": {
      "all_users": true,
      "all_channels": true,
      "all_groups": true,
      "all_users_channels": [
        "example"
      ],
      "all_groups_channels": [
        "example"
      ],
      "notifies": [
        {
          "target_type": "example",
          "target_uuid": "98531987-06b0-4d73-932a-191917e6ec57",
          "label": "example",
          "channels": [
            "example"
          ]
        }
      ]
    }
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the policies.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## List alarm policies

GET/v1/alarm-policies

Returns the organisation’s alarm policies, with how many it notifies by name; read one policy for the list. Pages by `page` and `per_page` (`limit` is the same as `per_page`); every page carries `current_page`, `per_page`, `last_page` and `total`.

Needs the scope `policies.view`.

### Query parameters

- `limit` (integer or null): The same as `per_page`, kept for existing clients.
- `include_total` (string or null): Ignored: `total` is always present. Values:`true``false``1``0`(an open set: new values may be added)
- `per_page` (integer or null): The page size, from 1 to 100.
- `page` (integer or null): The page to read, from 1; 1 when omitted. A page past the last answers no rows.

### Returns

`200 OK`:

One page of the organisation’s alarm policies.

Each item of the page:

- `uuid` (string): The policy’s uuid.
- `name` (string): The policy’s name.
- `default` (boolean): Whether this is the organisation’s default policy, which cannot be deleted.
- `all_users` (boolean): Whether every user of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_channels` (boolean): Whether every alarm channel of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `all_groups` (boolean): Whether every contact group of the organisation is notified for a warning incident (and a critical one while `critical_uses_warning` is true).
- `notifies_count` (integer): How many users, alarm channels and contact groups the policy notifies by name for a warning incident (and for a critical one while `critical_uses_warning` is true).
- `critical_uses_warning` (boolean): Whether critical incidents use the same routing as warning ones. While true, `critical` is null.
- `critical` (object or null): The routing for critical incidents, while `critical_uses_warning` is false: the three switches and how many users, alarm channels and contact groups it notifies by name for a critical incident.
  - `all_users` (boolean): Whether every user of the organisation is notified for a critical incident.
  - `all_channels` (boolean): Whether every alarm channel of the organisation is notified for a critical incident.
  - `all_groups` (boolean): Whether every contact group of the organisation is notified for a critical incident.
  - `notifies_count` (integer): How many users, alarm channels and contact groups the policy notifies by name for a critical incident.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/alarm-policies**

curl:

```bash
curl https://rest.watchtower15.com/v1/alarm-policies \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

foreach ($wt15->alarmPolicies->list()->autoPaging() as $alarmPolicy) { echo $alarmPolicy->uuid, "\n"; }
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

for await (const item of wt15.alarmPolicies.list()) {
  console.log(item.uuid);
}
```

Python:

```python
client = Client.from_environment()

for item in client.alarm_policies.list():
    print(item.uuid)
```

**Response (200 OK)**

```json
{
  "data": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example",
      "default": true,
      "all_users": true,
      "all_channels": true,
      "all_groups": true,
      "notifies_count": 1,
      "critical_uses_warning": true,
      "critical": {
        "all_users": true,
        "all_channels": true,
        "all_groups": true,
        "notifies_count": 1
      }
    }
  ],
  "current_page": 1,
  "per_page": 1,
  "last_page": 1,
  "total": 1
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the policies.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## Delete an alarm policy

DELETE/v1/alarm-policies/{policy\_uuid}

Deletes the policy. The default policy, and a policy an alarm rule or a report still uses, are refused. The answer has no body.

Needs the scope `policies.delete`.

### Headers

- `Idempotency-Key` (string): Any text of 1 to 255 visible ASCII characters. A repeat of the same request within 24 hours returns the first answer without running again (the response carries `Idempotent-Replayed: true`); the same key on a different request is refused 422 `invalid_request`.

### Path parameters

- `policy_uuid` (string (uuid), required): The uuid of the alarm policy in the path.

### Returns

`204 No Content`:

The alarm policy was deleted; there is no body.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**DELETE /v1/alarm-policies/{policy_uuid}**

curl:

```bash
curl -X DELETE https://rest.watchtower15.com/v1/alarm-policies/bef980be-2d82-440c-ab94-76d22f17bf41 \
  -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$wt15->alarmPolicies->delete('bef980be-2d82-440c-ab94-76d22f17bf41');
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

await wt15.alarmPolicies.delete('bef980be-2d82-440c-ab94-76d22f17bf41');
```

Python:

```python
client = Client.from_environment()

client.alarm_policies.delete('bef980be-2d82-440c-ab94-76d22f17bf41')
```

**Response (204 No Content)**

```http
HTTP/1.1 204 No Content
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the policies.delete scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid; `errors` names the parameters.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

Source: https://developer.watchtower15.com/api/reference/alarm-policies/
