> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.cail.health/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.cail.health/_mcp/server.

# Create an alert rule

POST https://staging.cail.health/v1/alert-rules
Content-Type: application/json

Creates a new alert rule for the operator’s organisation. Use the catalog endpoint to discover supported event types and recommended defaults. When `condition` is omitted, the catalog default for the event type is applied.

Reference: https://docs.cail.health/api-references/api-reference/configure-access-policy/create

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: cail-api
  version: 1.0.0
paths:
  /v1/alert-rules:
    post:
      operationId: create
      summary: Create an alert rule
      description: >-
        Creates a new alert rule for the operator’s organisation. Use the
        catalog endpoint to discover supported event types and recommended
        defaults. When `condition` is omitted, the catalog default for the event
        type is applied.
      tags:
        - subpackage_configureAccessPolicy
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: The newly-created alert rule.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateAlertRuleResponse'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAlertRuleRequest'
servers:
  - url: https://staging.cail.health
    description: https://staging.cail.health
components:
  schemas:
    AlertRuleConditionOperator:
      type: string
      enum:
        - <
        - '>'
        - <=
        - '>='
        - '='
      description: Comparison operator.
      title: AlertRuleConditionOperator
    AlertRuleCondition:
      type: object
      properties:
        field:
          type: string
          description: Field name on the alert event the condition evaluates against.
        operator:
          $ref: '#/components/schemas/AlertRuleConditionOperator'
          description: Comparison operator.
        value:
          type: number
          format: double
          description: Numeric threshold the field is compared against.
      required:
        - field
        - operator
        - value
      title: AlertRuleCondition
    CreateAlertRuleRequestChannel:
      type: string
      enum:
        - in-app
        - email
        - both
      description: Delivery channel. Defaults to `both`.
      title: CreateAlertRuleRequestChannel
    CreateAlertRuleRequest:
      type: object
      properties:
        name:
          type: string
          description: Human-readable name for the rule.
        eventType:
          type: string
          description: >-
            Event type code the rule listens for. Use the alert-rule catalog
            endpoint to discover available codes.
        condition:
          $ref: '#/components/schemas/AlertRuleCondition'
          description: >-
            Threshold condition that must evaluate true to fire the alert. Omit
            to use the event-type’s catalog default.
        channel:
          $ref: '#/components/schemas/CreateAlertRuleRequestChannel'
          description: Delivery channel. Defaults to `both`.
      required:
        - name
        - eventType
      title: CreateAlertRuleRequest
    AlertRuleResourceChannel:
      type: string
      enum:
        - in-app
        - email
        - both
      description: Delivery channel.
      title: AlertRuleResourceChannel
    AlertRuleResource:
      type: object
      properties:
        id:
          type: string
          description: Stable identifier of the alert rule.
        organizationId:
          type: string
          description: Stable identifier of the operator’s organisation.
        name:
          type: string
          description: Human-readable name for the rule.
        eventType:
          type: string
          description: Event-type code the rule listens for.
        condition:
          oneOf:
            - $ref: '#/components/schemas/AlertRuleCondition'
            - type: 'null'
          description: >-
            Threshold condition. Null when the rule fires on every event of its
            type.
        channel:
          $ref: '#/components/schemas/AlertRuleResourceChannel'
          description: Delivery channel.
        isActive:
          type: boolean
          description: Whether the rule fires when matched.
        createdAt:
          type: string
          description: ISO 8601 timestamp at which the rule was created.
        lastUpdated:
          type: string
          description: ISO 8601 timestamp of the most recent update.
      required:
        - id
        - organizationId
        - name
        - eventType
        - channel
        - isActive
        - createdAt
        - lastUpdated
      title: AlertRuleResource
    CreateAlertRuleResponse:
      type: object
      properties:
        data:
          $ref: '#/components/schemas/AlertRuleResource'
        message:
          type: string
          description: Human-readable acknowledgement.
      required:
        - data
        - message
      title: CreateAlertRuleResponse
  securitySchemes:
    auth0Bearer:
      type: http
      scheme: bearer

```

## Examples



**Request**

```json
{
  "name": "A&E diversion alert",
  "eventType": "a_and_e_diversion_rate"
}
```

**Response**

```json
{
  "data": {
    "id": "1d7d4e29-3b8e-4a01-a4f1-7e2a5b8c1d6e",
    "organizationId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
    "name": "A&E diversion alert",
    "eventType": "a_and_e_diversion_rate",
    "channel": "both",
    "isActive": true,
    "createdAt": "2026-05-13T14:21:00.000Z",
    "lastUpdated": "2026-05-13T14:21:00.000Z",
    "condition": {
      "field": "avoidanceRate",
      "operator": "<",
      "value": 0.6
    }
  },
  "message": "Alert rule created"
}
```

**SDK Code**

```python A new diversion-rate alert
import requests

url = "https://staging.cail.health/v1/alert-rules"

payload = {
    "name": "A&E diversion alert",
    "eventType": "a_and_e_diversion_rate"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript A new diversion-rate alert
const url = 'https://staging.cail.health/v1/alert-rules';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"name":"A&E diversion alert","eventType":"a_and_e_diversion_rate"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go A new diversion-rate alert
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://staging.cail.health/v1/alert-rules"

	payload := strings.NewReader("{\n  \"name\": \"A&E diversion alert\",\n  \"eventType\": \"a_and_e_diversion_rate\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby A new diversion-rate alert
require 'uri'
require 'net/http'

url = URI("https://staging.cail.health/v1/alert-rules")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"name\": \"A&E diversion alert\",\n  \"eventType\": \"a_and_e_diversion_rate\"\n}"

response = http.request(request)
puts response.read_body
```

```java A new diversion-rate alert
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://staging.cail.health/v1/alert-rules")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"name\": \"A&E diversion alert\",\n  \"eventType\": \"a_and_e_diversion_rate\"\n}")
  .asString();
```

```php A new diversion-rate alert
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://staging.cail.health/v1/alert-rules', [
  'body' => '{
  "name": "A&E diversion alert",
  "eventType": "a_and_e_diversion_rate"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp A new diversion-rate alert
using RestSharp;

var client = new RestClient("https://staging.cail.health/v1/alert-rules");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"name\": \"A&E diversion alert\",\n  \"eventType\": \"a_and_e_diversion_rate\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift A new diversion-rate alert
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "name": "A&E diversion alert",
  "eventType": "a_and_e_diversion_rate"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://staging.cail.health/v1/alert-rules")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```