# Sessions

After a user is authenticated, a *session* is created. For all subsequent requests to the API, specific rules based on the user's authentication scheme must be applied. If the session resource is deleted, the user will no longer be able to use the token issued in the last authentication and will need to log in again. The session is represented by the [`Session`](/data-models.md#session) class.

## API methods

## Get sessions

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

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

#### Query Parameters

| Name      | Type      | Description                                                                                                              |
| --------- | --------- | ------------------------------------------------------------------------------------------------------------------------ |
| sessionId | 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. |

#### 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": [
        {
            "sessionId": "soZIt6uj62fzs8ep4UvnNSxRXFryUiq3",
            "identity": {
                "userName": "999",
                "deviceName": "P01",
                "envName": "CashRegister",
                "authenticationType": "Bearer"
            },
            "startedAt": "2023-08-04T11:19:38.015Z",
            "expiresAt": "2023-08-04T23:19:38.015Z",
            "lastAccessAt": "2023-08-04T11:19:39.98Z",
            "_v": 2
        },
        {
            "sessionId": "Hq6563mjODIOwNa87Cgi295uNPlKeOqA",
            "identity": {
                "userName": "999",
                "deviceName": "BackOffice",
                "envName": "BackOffice",
                "authenticationType": "Bearer"
            },
            "startedAt": "2023-08-04T21:21:07.66Z",
            "expiresAt": "2023-08-05T09:21:07.66Z",
            "lastAccessAt": "2023-08-04T21:21:11.578Z",
            "_v": 4
        }
    ],
    "count": 2,
    "totalCount": 2
}
```

{% endtab %}
{% endtabs %}

## Get session

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

Result is of type [Session](/data-models.md#session).

#### Path Parameters

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

#### Headers

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

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

```javascript
{
    "sessionId": "Hq6563mjODIOwNa87Cgi295uNPlKeOqA",
    "identity":
    {
        "userName": "999",
        "deviceName": "BackOffice",
        "envName": "BackOffice",
        "authenticationType": "Bearer"
    },
    "startedAt": "2023-08-04T21:21:07.66Z",
    "expiresAt": "2023-08-05T09:21:07.66Z",
    "lastAccessAt": "2023-08-04T21:21:11.578Z",
    "_v": 7
}
```

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

## Delete session

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

Result is of type [Session](/data-models.md#session).

**Required rights**

No user rights are required to perform this method.

#### Path Parameters

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

#### Headers

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

{% tabs %}
{% tab title="204: No Content Successfully deleted." %}

```javascript
{
    "sessionId": "Hq6563mjODIOwNa87Cgi295uNPlKeOqA",
    "identity":
    {
        "userName": "999",
        "deviceName": "BackOffice",
        "envName": "BackOffice",
        "authenticationType": "Bearer"
    },
    "startedAt": "2023-08-04T21:21:07.66Z",
    "expiresAt": "2023-08-05T09:21:07.66Z",
    "lastAccessAt": "2023-08-04T21:21:11.578Z",
    "_v": 7
}
```

{% endtab %}

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

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

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developers.portos.sk/api-reference/sessions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
