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

# Create rule

` POST /alerts/rules `

Create rule

## Servers

- ` https://happyuptime.com/api/v1 `

## Authentication

The operation accepts these alternatives. Schemes within one alternative are required together.

### Alternative 1

- ` bearerAuth `: ` http `

  - HTTP scheme: ` bearer ` (hu_api_key)

  - API key with `hu_` prefix. Send exactly `Authorization: Bearer hu_...`. `X-API-Key` is not supported. Create keys in Dashboard → Settings → API Keys.

## Request body (required)

Content type: ` application/json `

- ` value `: type ` object `

  - Required fields: ` monitor_id `, ` alert_channel_id `, ` on_down `, ` on_recovery `, ` on_degraded `

  - ` monitor_id `: type ` string `

    - minLength: ` 1 `

  - ` alert_channel_id `: type ` string `

    - minLength: ` 1 `

  - ` on_down `: type ` boolean `

    - default: ` true `

  - ` on_recovery `: type ` boolean `

    - default: ` true `

  - ` on_degraded `: type ` boolean `

    - default: ` false `

## Responses

### ` 201 ` — Rule created

## Request examples

### cURL

```curl
curl -X POST 'https://happyuptime.com/api/v1/alerts/rules' \
  -H 'Authorization: Bearer YOUR_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "monitor_id": "string",
  "alert_channel_id": "string",
  "on_down": true,
  "on_recovery": true,
  "on_degraded": false
}'
```

### JavaScript

```javascript
const response = await fetch('https://happyuptime.com/api/v1/alerts/rules', {
  method: 'POST',
  headers: {
      "Authorization": "Bearer YOUR_API_TOKEN",
      "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "monitor_id": "string",
    "alert_channel_id": "string",
    "on_down": true,
    "on_recovery": true,
    "on_degraded": false
  })
});

const data = await response.json();
console.log(data);
```

### Python

```python
import requests

headers = {
    'Authorization': 'Bearer YOUR_API_TOKEN'
}

response = requests.post('https://happyuptime.com/api/v1/alerts/rules', headers=headers, json={
  "monitor_id": "string",
  "alert_channel_id": "string",
  "on_down": true,
  "on_recovery": true,
  "on_degraded": false
})
print(response.json())
```