# Routing Rules API Reference

Source: https://instatus.com/help/api/routing-rules

## Possible Values for fields

**Action Type**

| Value                         | Description                          |
| ----------------------------- | ------------------------------------ |
| `NOTIFY_TEAM`                 | Notify a specific team               |
| `NOTIFY_TEAM_MEMBER`     | Notify a specific team member   |
| `NOTIFY_CURRENT_ON_CALL_USER` | Notify the current on-call user      |
| `NOTIFY_NEXT_ON_CALL_USER`    | Notify the next on-call user         |
| `NOTIFY_ALL_ON_CALL_MEMBERS`  | Notify all members currently on-call |

**Assertion Type**

| Value                 | Description                                 |
| --------------------- | ------------------------------------------- |
| `IMPACT`              | Asserts the impact of an event              |
| `TITLE`               | Asserts the title of an event               |
| `DESCRIPTION`         | Asserts the description of an event         |
| `AFFECTED_COMPONENTS` | Asserts the affected components of an event |

**Comparison Types**

| Value                    | Description                                          |
| ------------------------ | ---------------------------------------------------- |
| `EQUALS`                 | Checks if the value is equal                         |
| `NOT_EQUALS`             | Checks if the value is not equal                     |
| `IS_EMPTY`               | Checks if the value is empty                         |
| `NOT_EMPTY`              | Checks if the value is not empty                     |
| `GREATER_THAN`           | Checks if the value is greater than                  |
| `GREATER_THAN_OR_EQUALS` | Checks if the value is greater than or equal         |
| `LESS_THAN`              | Checks if the value is less than                     |
| `LESS_THAN_OR_EQUALS`    | Checks if the value is less than or equal            |
| `CONTAINS`               | Checks if the value contains a specified substring   |
| `NOT_CONTAINS`           | Checks if the value does not contain a substring     |
| `HAS_KEY`                | Checks if an object has a specific key               |
| `NOT_HAS_KEY`            | Checks if an object does not have a specific key     |
| `HAS_VALUE`              | Checks if an object has a specific value             |
| `NOT_HAS_VALUE`          | Checks if an object does not have a specific value   |
| `IS_NULL`                | Checks if the value is null                          |
| `NOT_NULL`               | Checks if the value is not null                      |
| `STARTS_WITH`            | Checks if the value starts with a specific substring |
| `ENDS_WITH`              | Checks if the value ends with a specific substring   |

## Get Routing Rules

**Endpoint:**

```bash
GET /:page_id/routing-rules
```

**Example request**

```bash
GET /1/routing-rules
```

**Example response**

```json
{
  "routingRules": [
    {
      "id": "1",
      "siteId": "pageId",
      "assertions": [
        {
          "id": "1",
          "routingRuleId": "1",
          "type": "TITLE",
          "comparison": "CONTAINS",
          "value": "value1"
        },
        {
          "id": "2",
          "routingRuleId": "1",
          "type": "TITLE",
          "comparison": "CONTAINS",
          "value": "value2"
        }
      ],
      "actions": [
        {
          "id": "1",
          "routingRuleId": "1",
          "type": "NOTIFY_TEAM_MEMBER",
          "targetId": "value1"
        },
        {
          "id": "2",
          "routingRuleId": "1",
          "type": "NOTIFY_TEAM_MEMBER",
          "targetId": "member@platform.com"
        }
      ],
      "createdAt": "2021-09-29T00:00:00.000Z",
      "updatedAt": "2021-09-29T00:00:00.000Z",
      "order": 1
    }
  ]
}
```

## Create Routing Rule

**Endpoint:**

```bash
POST /routing-rules
```

Keep in mind in actions `targetId` can be a team member email or a team id depending on the type of the action.

**Example request**

```json
{
  "routingRule": {
    "assertions": [
      {
        "id": "1",
        "routingRuleId": "1",
        "type": "TITLE",
        "comparison": "CONTAINS",
        "value": "value1"
      },
      {
        "id": "2",
        "routingRuleId": "1",
        "type": "TITLE",
        "comparison": "CONTAINS",
        "value": "value2"
      }
    ],
    "actions": [
      {
        "id": "1",
        "routingRuleId": "1",
        "type": "NOTIFY_TEAM_MEMBER",
        "targetId": "member2@platform.com"
      },
      {
        "id": "2",
        "routingRuleId": "1",
        "type": "NOTIFY_TEAM_MEMBER",
        "targetId": "member@platform.com"
      }
    ],
    "order": 1,
    "siteId": "site-id-1"
  },
  "message": "Routing rule updated successfully"
}
```

**Example response**

```json
{
  "routingRule": {
    "id": "routing-rule-id-1",
    "order": 1,
    "siteId": "site123",
    "updatedAt": "2021-09-01T12:00:00Z",
    "createdAt": "2021-09-01T12:00:00Z"
  },
  "message": "Routing rule created successfully."
}
```

## Update Routing Rule

**Endpoint:**

```bash
PUT /routing-rules/:id
```

**Example request**

```bash
PUT /routing-rules/routing-rule-id-1
```

```json
{
  "routingRule": {
    "id": "routing-rule-id-1",
    "assertions": [
      {
        "id": "assertion-id-1",
        "routingRuleId": "routing-rule-id-1",
        "comparison": "CONTAINS",
        "value": "Issue With X",
        "type": "TITLE"
      }
    ],
    "order": 1,
    "siteId": "site-id-1",
    "updatedAt": "2021-09-01T12:00:00Z",
    "createdAt": "2021-05-01T12:00:00Z"
  },
  "message": "Routing rule updated successfully"
}
```

**Example response**

```json
{
  "routingRule": {
    "id": "routing-rule-id-1",
    "assertions": [
      {
        "id": "assertion-id-1",
        "routingRuleId": "routing-rule-id-1",
        "comparison": "CONTAINS",
        "value": "Issue With X",
        "type": "TITLE"
      }
    ],
    "order": 1,
    "siteId": "site-id-1",
    "updatedAt": "2024-08-09T12:00:00Z",
    "createdAt": "2021-05-01T12:00:00Z"
  },
  "message": "Routing rule updated successfully"
}
```

## Delete Routing Rule

**Endpoint:**

```bash
DELETE /routing-rules/:id
```

**Example request**

```bash
DELETE /routing-rules/routing-rule-id-1
```

**Example response**

```json
{
  "message": "Routing rule deleted successfully."
}
```
