# Referencia de la API de reglas de enrutamiento

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

## Valores posibles de los campos

**Tipo de acción**

| Valor                         | Descripción                          |
| ----------------------------- | ------------------------------------ |
| `NOTIFY_TEAM`                 | Notificar a un equipo concreto               |
| `NOTIFY_WORKSPACE_MEMBER`     | Notificar a un miembro concreto del espacio de trabajo   |
| `NOTIFY_CURRENT_ON_CALL_USER` | Notificar a la persona de guardia actual      |
| `NOTIFY_NEXT_ON_CALL_USER`    | Notificar a la siguiente persona de guardia         |
| `NOTIFY_ALL_ON_CALL_MEMBERS`  | Notificar a todos los miembros que estén de guardia |

**Tipo de comprobación**

| Valor                 | Descripción                                 |
| --------------------- | ------------------------------------------- |
| `IMPACT`              | Comprueba el impacto de un evento              |
| `TITLE`               | Comprueba el título de un evento               |
| `DESCRIPTION`         | Comprueba la descripción de un evento         |
| `AFFECTED_COMPONENTS` | Comprueba los componentes afectados de un evento |

**Tipos de comparación**

| Valor                    | Descripción                                          |
| ------------------------ | ---------------------------------------------------- |
| `EQUALS`                 | Comprueba si el valor es igual                         |
| `NOT_EQUALS`             | Comprueba si el valor no es igual                     |
| `IS_EMPTY`               | Comprueba si el valor está vacío                         |
| `NOT_EMPTY`              | Comprueba si el valor no está vacío                     |
| `GREATER_THAN`           | Comprueba si el valor es mayor                  |
| `GREATER_THAN_OR_EQUALS` | Comprueba si el valor es mayor o igual         |
| `LESS_THAN`              | Comprueba si el valor es menor                     |
| `LESS_THAN_OR_EQUALS`    | Comprueba si el valor es menor o igual            |
| `CONTAINS`               | Comprueba si el valor contiene una subcadena concreta   |
| `NOT_CONTAINS`           | Comprueba si el valor no contiene una subcadena     |
| `HAS_KEY`                | Comprueba si un objeto tiene una clave concreta               |
| `NOT_HAS_KEY`            | Comprueba si un objeto no tiene una clave concreta     |
| `HAS_VALUE`              | Comprueba si un objeto tiene un valor concreto             |
| `NOT_HAS_VALUE`          | Comprueba si un objeto no tiene un valor concreto   |
| `IS_NULL`                | Comprueba si el valor es null                          |
| `NOT_NULL`               | Comprueba si el valor no es null                      |
| `STARTS_WITH`            | Comprueba si el valor empieza por una subcadena concreta |
| `ENDS_WITH`              | Comprueba si el valor termina con una subcadena concreta   |

## Obtener las reglas de enrutamiento

**Endpoint:**

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

**Petición de ejemplo**

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

**Respuesta de ejemplo**

```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_WORKSPACE_MEMBER",
          "targetId": "value1"
        },
        {
          "id": "2",
          "routingRuleId": "1",
          "type": "NOTIFY_WORKSPACE_MEMBER",
          "targetId": "member@platform.com"
        }
      ],
      "createdAt": "2021-09-29T00:00:00.000Z",
      "updatedAt": "2021-09-29T00:00:00.000Z",
      "order": 1
    }
  ]
}
```

## Crear una regla de enrutamiento

**Endpoint:**

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

Ten en cuenta que, en las acciones, `targetId` puede ser el correo de un miembro del espacio de trabajo o el ID de un equipo, según el tipo de acción.

**Petición de ejemplo**

```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_WORKSPACE_MEMBER",
        "targetId": "member2@platform.com"
      },
      {
        "id": "2",
        "routingRuleId": "1",
        "type": "NOTIFY_WORKSPACE_MEMBER",
        "targetId": "member@platform.com"
      }
    ],
    "order": 1,
    "siteId": "site-id-1"
  },
  "message": "Routing rule updated successfully"
}
```

**Respuesta de ejemplo**

```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."
}
```

## Actualizar una regla de enrutamiento

**Endpoint:**

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

**Petición de ejemplo**

```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"
}
```

**Respuesta de ejemplo**

```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"
}
```

## Eliminar una regla de enrutamiento

**Endpoint:**

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

**Petición de ejemplo**

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

**Respuesta de ejemplo**

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