# Riferimento API delle regole di instradamento

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

## Valori possibili per i campi

**Tipo di azione**

| Valore                        | Descrizione                          |
| ----------------------------- | ------------------------------------ |
| `NOTIFY_TEAM`                 | Avvisa un team specifico             |
| `NOTIFY_WORKSPACE_MEMBER`     | Avvisa un membro specifico del workspace |
| `NOTIFY_CURRENT_ON_CALL_USER` | Avvisa la persona reperibile attuale |
| `NOTIFY_NEXT_ON_CALL_USER`    | Avvisa la prossima persona reperibile |
| `NOTIFY_ALL_ON_CALL_MEMBERS`  | Avvisa tutti i membri attualmente reperibili |

**Tipo di asserzione**

| Valore                | Descrizione                                 |
| --------------------- | ------------------------------------------- |
| `IMPACT`              | Verifica l'impatto di un evento             |
| `TITLE`               | Verifica il titolo di un evento             |
| `DESCRIPTION`         | Verifica la descrizione di un evento        |
| `AFFECTED_COMPONENTS` | Verifica i componenti interessati da un evento |

**Tipi di confronto**

| Valore                   | Descrizione                                          |
| ------------------------ | ---------------------------------------------------- |
| `EQUALS`                 | Verifica se il valore è uguale                       |
| `NOT_EQUALS`             | Verifica se il valore è diverso                      |
| `IS_EMPTY`               | Verifica se il valore è vuoto                        |
| `NOT_EMPTY`              | Verifica se il valore non è vuoto                    |
| `GREATER_THAN`           | Verifica se il valore è maggiore                     |
| `GREATER_THAN_OR_EQUALS` | Verifica se il valore è maggiore o uguale            |
| `LESS_THAN`              | Verifica se il valore è minore                       |
| `LESS_THAN_OR_EQUALS`    | Verifica se il valore è minore o uguale              |
| `CONTAINS`               | Verifica se il valore contiene una data sottostringa |
| `NOT_CONTAINS`           | Verifica se il valore non contiene una sottostringa  |
| `HAS_KEY`                | Verifica se un oggetto ha una chiave specifica       |
| `NOT_HAS_KEY`            | Verifica se un oggetto non ha una chiave specifica   |
| `HAS_VALUE`              | Verifica se un oggetto ha un valore specifico        |
| `NOT_HAS_VALUE`          | Verifica se un oggetto non ha un valore specifico    |
| `IS_NULL`                | Verifica se il valore è null                         |
| `NOT_NULL`               | Verifica se il valore non è null                     |
| `STARTS_WITH`            | Verifica se il valore inizia con una data sottostringa |
| `ENDS_WITH`              | Verifica se il valore termina con una data sottostringa |

## Ottenere le regole di instradamento

**Endpoint:**

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

**Esempio di richiesta**

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

**Esempio di risposta**

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

## Creare una regola di instradamento

**Endpoint:**

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

Tieni presente che nelle azioni `targetId` può essere l'email di un membro del workspace o l'id di un team, a seconda del tipo di azione.

**Esempio di richiesta**

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

**Esempio di risposta**

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

## Aggiornare una regola di instradamento

**Endpoint:**

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

**Esempio di richiesta**

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

**Esempio di risposta**

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

## Eliminare una regola di instradamento

**Endpoint:**

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

**Esempio di richiesta**

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

**Esempio di risposta**

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