# Documentazione API V1

## Prima di cominciare

Effettuare le richieste qui descritte espone il sistema a cui vi state collegando, quindi richiede che eventuali credenziali e token siano conservati in modo sicuro.

## Ottenere il Token della Sessione

<mark style="color:green;">`POST`</mark> `https://api.ohmautomation.io/control/v1/auth`

Questo *endpoint* permette di ottenere il token della sessione, necessario per effettuare tutte le altre richieste.

#### Headers

| Name         | Type   | Description        |
| ------------ | ------ | ------------------ |
| Content-Type | string | `application/json` |

#### Request Body

| Name                                       | Type   | Description     |
| ------------------------------------------ | ------ | --------------- |
| username<mark style="color:red;">\*</mark> | string | Nome utente     |
| password<mark style="color:red;">\*</mark> | string | Password utente |

{% tabs %}
{% tab title="200 " %}

```
{
  "token": "r:qwertyuiop1234567890"
}
```

{% endtab %}
{% endtabs %}

## Eliminare la Sessione

<mark style="color:green;">`POST`</mark> `https://api.ohmautomation.io/control/v1/logout`

Questo *endpoint* permette di eliminare la sessione, così da rendere il token inutilizzabile.

#### Headers

| Name                                              | Type   | Description                       |
| ------------------------------------------------- | ------ | --------------------------------- |
| X-Session-Token<mark style="color:red;">\*</mark> | string | Token della sessione da eliminare |

{% tabs %}
{% tab title="200 " %}

```
{
  "token": <deleted_token>
}
```

{% endtab %}
{% endtabs %}

## JSON delle Scorciatoie

<mark style="color:blue;">`GET`</mark> `https://api.ohmautomation.io/control/v1/shortcuts?token=abc`

Questo *endpoint* permette di ottenere un *JSON* con la configurazione delle scorciatoie dell'utente a cui corrisponde il token.

#### Query Parameters

| Name                                    | Type   | Description          |
| --------------------------------------- | ------ | -------------------- |
| token<mark style="color:red;">\*</mark> | string | Token della sessione |

{% tabs %}
{% tab title="200 JSON con la configurazione delle scorciatoie" %}

```
{
    "shortcuts": [
        {
            "askConfirm": false,
            "category": "shortcut",
            "color": "#117ED9",
            "desc": "Spegni tutte le luci",
            "icon": "house_2",
            "id": "abc123",
            "itemACL": [
                {
                    "id": "qwerty",
                    "read": true,
                    "write": true
                }
            ],
            "name": "Demo",
            "objectId": "system",
            "operations": [
                {
                    "function": {
                        "args": {},
                        "name": "turn_off_all_lights"
                    },
                    "objectId": "system",
                    "timer": {
                        "days": 0,
                        "hours": 0,
                        "min": 0,
                        "sec": 0
                    }
                }
            ],
            "parameters": []
        },
        {
            "askConfirm": false,
            "category": "shortcut",
            "color": "#FFB300",
            "desc": "Attiva/Disattiva TV",
            "icon": "tv",
            "id": "abc1234",
            "itemACL": [
                {
                    "id": "qwerty",
                    "read": true,
                    "write": true
                }
            ],
            "name": "TV",
            "objectId": "ac278aa6-fdd8-4899-960e-55ad702452ce",
            "operations": [
                {
                    "function": {
                        "args": {},
                        "name": "toggle"
                    },
                    "objectId": "ac278aa6-fdd8-4899-960e-55ad702452ce",
                    "timer": {
                        "days": 0,
                        "hours": 0,
                        "min": 0,
                        "sec": 0
                    }
                }
            ],
            "parameters": []
        },
        {
            "askConfirm": false,
            "category": "shortcut",
            "color": "#880E4F",
            "desc": "Apri/Chiudi cancello",
            "icon": "gate",
            "id": "abc12345
            "itemACL": [
                {
                    "id": "qwerty",
                    "read": true,
                    "write": true
                }
            ],
            "name": "Cancello",
            "objectId": "",
            "operations": [
                {
                    "function": {
                        "args": {},
                        "name": "on"
                    },
                    "objectId": "a41f6a53-3b69-44e4-abf2-fed4bed8785c",
                    "timer": {
                        "days": 0,
                        "hours": 0,
                        "min": 0,
                        "sec": 0
                    }
                }
            ],
            "parameters": []
        }
    ]
}
```

{% endtab %}
{% endtabs %}

È possibile evitare l'uso del token nell'url e allegarlo agli *Headers*.

## JSON Scorciatoie con Headers

<mark style="color:blue;">`GET`</mark> `https://api.ohmautomation.io/control/v1/shortcuts`

Come il precedente metodo, anche in questo caso otteniamo un *JSON* con la configurazione delle scorciatoie, ma il token lo indichiamo negli *Headers*. Consigliamo questa soluzione in quanto non espone il token nell'url.&#x20;

#### Headers

| Name                                              | Type   | Description          |
| ------------------------------------------------- | ------ | -------------------- |
| Content-Type                                      | string | `application/json`   |
| X-Session-Token<mark style="color:red;">\*</mark> | string | Token della sessione |

{% tabs %}
{% tab title="200 " %}

```
{
    "shortcuts": [
        {
            "askConfirm": false,
            "category": "shortcut",
            "color": "#117ED9",
            "desc": "Spegni tutte le luci",
            "icon": "house_2",
            "id": "abc123",
            "itemACL": [
                {
                    "id": "qwerty",
                    "read": true,
                    "write": true
                }
            ],
            "name": "Demo",
            "objectId": "system",
            "operations": [
                {
                    "function": {
                        "args": {},
                        "name": "turn_off_all_lights"
                    },
                    "objectId": "system",
                    "timer": {
                        "days": 0,
                        "hours": 0,
                        "min": 0,
                        "sec": 0
                    }
                }
            ],
            "parameters": []
        },
        {
            "askConfirm": false,
            "category": "shortcut",
            "color": "#FFB300",
            "desc": "Attiva/Disattiva TV",
            "icon": "tv",
            "id": "abc1234",
            "itemACL": [
                {
                    "id": "qwerty",
                    "read": true,
                    "write": true
                }
            ],
            "name": "TV",
            "objectId": "ac278aa6-fdd8-4899-960e-55ad702452ce",
            "operations": [
                {
                    "function": {
                        "args": {},
                        "name": "toggle"
                    },
                    "objectId": "ac278aa6-fdd8-4899-960e-55ad702452ce",
                    "timer": {
                        "days": 0,
                        "hours": 0,
                        "min": 0,
                        "sec": 0
                    }
                }
            ],
            "parameters": []
        },
        {
            "askConfirm": false,
            "category": "shortcut",
            "color": "#880E4F",
            "desc": "Apri/Chiudi cancello",
            "icon": "gate",
            "id": "abc12345
            "itemACL": [
                {
                    "id": "qwerty",
                    "read": true,
                    "write": true
                }
            ],
            "name": "Cancello",
            "objectId": "",
            "operations": [
                {
                    "function": {
                        "args": {},
                        "name": "on"
                    },
                    "objectId": "a41f6a53-3b69-44e4-abf2-fed4bed8785c",
                    "timer": {
                        "days": 0,
                        "hours": 0,
                        "min": 0,
                        "sec": 0
                    }
                }
            ],
            "parameters": []
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Esecuzione della Scorciatoia

<mark style="color:green;">`POST`</mark> `https://api.ohmautomation.io/control/v1/shortcut`

#### Headers

| Name                                              | Type   | Description          |
| ------------------------------------------------- | ------ | -------------------- |
| Content-Type                                      | string | `application/json`   |
| X-Session-Token<mark style="color:red;">\*</mark> | string | Token della sessione |

#### Request Body

| Name                                      | Type   | Description          |
| ----------------------------------------- | ------ | -------------------- |
| id<mark style="color:red;">\*</mark>      | string | ID della scorciatoia |
| command<mark style="color:red;">\*</mark> | string | `run`                |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Visualizza Scorciatoia via Web

<mark style="color:blue;">`GET`</mark> `https://api.ohmautomation.io/control/v1/shortcut?token=abc&link=0&lang=it`

Questo *endpoint* permette la visualizzazione e l'esecuzione di una scorciatoia.

#### Query Parameters

| Name                                    | Type   | Description                                 |
| --------------------------------------- | ------ | ------------------------------------------- |
| token<mark style="color:red;">\*</mark> | string | Token della sessione                        |
| id<mark style="color:red;">\*</mark>    | string | ID della scorciatoia                        |
| lang                                    | string | Lingua di visualizzazione (`en` di default) |

{% tabs %}
{% tab title="200 Pagina Web che permette l'esecuzione della scorciatoia" %}

```
HTML
```

{% endtab %}
{% endtabs %}
