> For the complete documentation index, see [llms.txt](https://developers.portos.sk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.portos.sk/api-reference/devices.md).

# Devices

In the PORTOS ecosystem, each cash register, mobile cashier, BackOffice, or any other software application is represented by a device that stores its settings and preferences.

Device is represented by [`Device`](/data-models.md#device) class.

## API methods

## Get devices

<mark style="color:blue;">`GET`</mark> `http://{server-address}/devices`

Returns all devices that matches query parameters. Result is of type [`QueryResult<Device>`](/data-models.md#queryresult).

#### Query Parameters

| Name     | Type      | Description                                                                                                              |
| -------- | --------- | ------------------------------------------------------------------------------------------------------------------------ |
| name     | string    | Supports NData syntax.                                                                                                   |
| $skip    | int       | Pagination property. Describing number of records to skip from beginning of result collection.                           |
| $take    | int       | Pagination property. Maximum count of items to be returned.                                                              |
| $sort    | string\[] | <p>Comma separated list of property names. Please see NData syntax.<br></p>                                              |
| $count   | bool      | If set to `true`, response will not contain `items` collection. Use to get resource count, not the resources themselves. |
| isActive | bool      | Supports NData syntax.                                                                                                   |
| envName  | string    | Supports NData syntax.                                                                                                   |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

{% tabs %}
{% tab title="200: OK Successful response" %}

```javascript
{
    "items":
    [
        {
            "name": "BackOffice",
            "isActive": true,
            "envName": "BackOffice",
            "description": "BackOffice",
            "roles":
            [
                "admin"
            ],
            "preferences":
            {},
            "settings":
            {},
            "_v": 1
        },
        {
            "name": "P01",
            "isActive": true,
            "envName": "CashRegister",
            "description": "Pokladnica 1",
            "roles":
            [
                "sale",
                "statsCurrent",
                "statsTicketsCurrent",
                "openDrawer",
                "negativeSale",
                "overviewSalesReport",
                "ticketSplit",
                "storno",
                "stats",
                "statsPlus",
                "cashTransfer",
                "allTickets",
                "ticketSetDiscount"
            ],
            "preferences":
            {},
            "settings":
            {
                "MaxQuantity": "50",
                "OpenedPrices": "false",
                "DefaultFiscalName": "eKasa",
                "DefaultOrderEndpointName": "USB",
                "DefaultStockName": "S01"
            },
            "_v": 10
        },
        {
            "name": "PDA1",
            "isActive": true,
            "envName": "PDA",
            "description": "Mobile cashier 1",
            "roles":
            [
                "sale",
                "statsCurrent",
                "statsTicketsCurrent",
                "openDrawer",
                "negativeSale",
                "overviewSalesReport",
                "ticketSplit",
                "storno",
                "stats",
                "statsPlus",
                "cashTransfer",
                "allTickets",
                "ticketSetDiscount",
                "admin"
            ],
            "preferences":
            {},
            "settings":
            {
                "DefaultFiscalName": "eKasa",
                "DefaultStockName": "S01"
            },
            "_v": 11
        },
        {
            "name": "Link",
            "isActive": true,
            "envName": "Tool",
            "description": "PORTOS Link",
            "roles":
            [
                "admin"
            ],
            "preferences":
            {},
            "settings":
            {},
            "_v": 1
        }
    ],
    "count": 4,
    "totalCount": 4
}
```

{% endtab %}
{% endtabs %}

## Get device by name

<mark style="color:blue;">`GET`</mark> `http://{server-address}/devices/{name}`

Result is of type [Device](/data-models.md#device).

#### Path Parameters

| Name                                   | Type   | Description         |
| -------------------------------------- | ------ | ------------------- |
| name<mark style="color:red;">\*</mark> | string | Unique device name. |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

{% tabs %}
{% tab title="200: OK Resource found." %}

```javascript
{
    "name": "BackOffice",
    "isActive": true,
    "envName": "BackOffice",
    "description": "BackOffice",
    "roles":
    [
        "admin"
    ],
    "preferences":
    {},
    "settings":
    {},
    "_v": 1
}
```

{% endtab %}

{% tab title="404: Not Found Given resource was not found." %}

```javascript
{
    "title": "Zdroj nebol nájdený",
    "status": 404
}
```

{% endtab %}
{% endtabs %}

## Create device

<mark style="color:green;">`POST`</mark> `http://{server-address}/devices`

Creates new device. Result is of type [Device](/data-models.md#device).

**Required rights**

Authorized user must have `DeviceCreate` [right ](/user-rights.md)assigned.

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

#### Request Body

| Name                                     | Type   | Description      |
| ---------------------------------------- | ------ | ---------------- |
| (body)<mark style="color:red;">\*</mark> | Device | Model to create. |

{% tabs %}
{% tab title="201: Created Successfuly created." %}

```javascript
{
    "name": "BackOffice",
    "isActive": true,
    "envName": "BackOffice",
    "description": "BackOffice",
    "roles":
    [
        "admin"
    ],
    "preferences":
    {},
    "settings":
    {},
    "_v": 1
}
```

{% endtab %}
{% endtabs %}

## Create or update device

<mark style="color:orange;">`PUT`</mark> `http://{server-address}/devices/{name}`

Creates new or updates existing device. Result is of type [Device](/data-models.md#device).

**Required rights**

Authorized user must have assigned `DeviceCreate` or `DeviceUpdate` [right](/user-rights.md).

#### Path Parameters

| Name                                   | Type   | Description         |
| -------------------------------------- | ------ | ------------------- |
| name<mark style="color:red;">\*</mark> | string | Unique device name. |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

#### Request Body

| Name                                     | Type   | Description                |
| ---------------------------------------- | ------ | -------------------------- |
| (body)<mark style="color:red;">\*</mark> | Device | Model to create or update. |

{% tabs %}
{% tab title="200: OK Successfuly created or updated." %}

```javascript
{
    "name": "BackOffice",
    "isActive": true,
    "envName": "BackOffice",
    "description": "BackOffice",
    "roles":
    [
        "admin"
    ],
    "preferences":
    {},
    "settings":
    {},
    "_v": 2
}
```

{% endtab %}
{% endtabs %}

## Delete device by name

<mark style="color:red;">`DELETE`</mark> `http://{server-address}/devices/{name}`

**Required rights**

Authorized user must have `DeviceDelete` [right ](/user-rights.md)assigned.

#### Path Parameters

| Name                                   | Type   | Description         |
| -------------------------------------- | ------ | ------------------- |
| name<mark style="color:red;">\*</mark> | string | Unique device name. |

#### Headers

| Name                                            | Type   | Description                                    |
| ----------------------------------------------- | ------ | ---------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Authorization header with authorization token. |

{% tabs %}
{% tab title="200: OK Successfuly deleted." %}

```javascript
{
    "name": "BackOffice",
    "isActive": true,
    "envName": "BackOffice",
    "description": "BackOffice",
    "roles":
    [
        "admin"
    ],
    "preferences":
    {},
    "settings":
    {},
    "_v": 1
}
```

{% endtab %}

{% tab title="404: Not Found Given resource was not found." %}

```javascript
{
    "title": "Zdroj nebol nájdený",
    "status": 404
}
```

{% endtab %}
{% endtabs %}
