# Stocks

Each Product (represented by [`Plu`](/data-models.md#plu) model) is associated with stock through its `StockName` property. Stocks are represented by [`Stock`](/data-models.md#stock) class and uniquely identified by their names (`stock.Name` property). A stock can group multiple products (e.g. stock called "Menu" that contains products that can be listed in cash register and stock called "Material" that contains raw materials and other resources in kitchen). Each product has a unique code (`plu.Code` property) within its respective stock.

## API methods

## Get stocks

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

Returns all stocks that matches query parameters. Result is of type [`QueryResult<Stock>`](/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. |

#### 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": "S01",
            "description": "Menu",
            "_v": 2
        },
        {
            "name": "S11",
            "description": "Suroviny a zásoby",
            "_v": 2
        }
    ],
    "count": 2,
    "totalCount": 2
}
```

{% endtab %}
{% endtabs %}

## Get stock by name

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

Result is of type [Stock](/data-models.md#stock).

#### Path Parameters

| Name                                   | Type   | Description        |
| -------------------------------------- | ------ | ------------------ |
| name<mark style="color:red;">\*</mark> | string | Unique stock 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": "S01",
    "description": "Menu",
    "_v": 1
}
```

{% endtab %}

{% tab title="404: Not Found Resource not found." %}

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

{% endtab %}
{% endtabs %}

## Create stock

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

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

**Required rights**

Authorized user must have `StockCreate` [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> | Stock | Model to create |

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

```javascript
{
    "name": "S01",
    "description": "Menu",
    "_v": 2
}
```

{% endtab %}
{% endtabs %}

## Create or update stock

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

Updates existing or creates new stock. Result is of type [Stock](/data-models.md#stock).

**Required rights**

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

#### Path Parameters

| Name                                   | Type   | Description        |
| -------------------------------------- | ------ | ------------------ |
| name<mark style="color:red;">\*</mark> | string | Unique stock 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> | Stock | Model to create or update. |

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

```javascript
{
    "name": "S01",
    "description": "Menu",
    "_v": 2
}
```

{% endtab %}
{% endtabs %}

## Delete stock by name

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

**Required rights**

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

#### Path Parameters

| Name                                   | Type   | Description        |
| -------------------------------------- | ------ | ------------------ |
| name<mark style="color:red;">\*</mark> | string | Unique stock 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": "S01",
    "description": "Menu",
    "_v": 2
}
```

{% 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/stocks.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.
