> ## Documentation Index
> Fetch the complete documentation index at: https://apidocs.noyax.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create critical stock definition

> Adds a critical stock definition to the product for a warehouse.

A critical stock definition can only be added to a product whose `StockType` is not `1` (no stock tracking) (`2410`).

`WarehouseId` is required; a product can have at most one critical stock definition per warehouse (`2403`).

* `MinStock` and `MaxStock` cannot be negative.
* When `MaxStock` is greater than 0, it cannot be less than `MinStock` (`2406`); `MaxStock: 0` means there is no upper limit.
* `MaxStockControl`, `MinStockControl` and `NegativeStockControl` each take the following values:

| Value | Meaning                |
| ----- | ---------------------- |
| `0`   | Continue the operation |
| `1`   | Warn the user          |
| `2`   | Stop the operation     |

* `MaxStockControl`: when stock exceeds `MaxStock`.
* `MinStockControl`: when stock falls below `MinStock`.
* `NegativeStockControl`: when an operation would make stock negative.


## OpenAPI

````yaml api-reference/openapi.json POST /api/v1/products/{productId}/critical-stock
openapi: 3.1.1
info:
  title: Noyax API
  description: Server-to-server API for integrations to access Noyax data.
  version: '1.0'
servers:
  - url: https://api.noyax.com
security:
  - Bearer: []
tags:
  - name: Sections
  - name: Warehouses
  - name: Product Critical Stock
  - name: Product groups
  - name: Product Parameter Definitions
  - name: Product Parameters
  - name: Product Prices
  - name: Products
  - name: Cities
  - name: Countries
  - name: Currencies
  - name: Districts
  - name: Shipment Definitions
  - name: Units
  - name: VAT rates
  - name: Customer Addresses
  - name: Customer Bank Accounts
  - name: Customer Definitions
  - name: Customer Group Members
  - name: Customer Links
  - name: Customer Parameters
  - name: Customer Representatives
  - name: Customers
  - name: Customer Statement
  - name: Customer Telephones
paths:
  /api/v1/products/{productId}/critical-stock:
    post:
      tags:
        - Product Critical Stock
      summary: Create critical stock definition
      description: >-
        Adds a critical stock definition to the product for a warehouse. A
        product can have at most one definition per warehouse.
      parameters:
        - name: productId
          in: path
          description: Product ID.
          required: true
          schema:
            type: string
            format: uuid
        - name: X-UserID
          in: header
          description: >-
            ID of the Noyax user the request is made on behalf of. Written to
            the audit fields of created, updated and deleted records.
          required: true
          schema:
            minimum: 1
            type: integer
            format: int32
        - name: X-CompanyID
          in: header
          description: >-
            ID of the company. The user must be assigned to this company. All
            reads and writes are limited to this company.
          required: true
          schema:
            minimum: 1
            type: integer
            format: int32
        - name: X-PeriodID
          in: header
          description: >-
            ID of the accounting period. Optional for customer endpoints; if
            sent, it is written to created records.
          schema:
            minimum: 1
            type: integer
            format: int32
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ProductCriticalStockRequestDto'
          text/json:
            schema:
              $ref: '#/components/schemas/ProductCriticalStockRequestDto'
          application/*+json:
            schema:
              $ref: '#/components/schemas/ProductCriticalStockRequestDto'
        required: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DataResultOfProductCriticalStockDto'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResult'
              example:
                Success: false
                ResultCode: '2410'
                Message: >-
                  A critical stock definition cannot be added for a product with
                  StockType 1 (no stock tracking).
                Errors:
                  - Code: '2410'
                    Message: >-
                      A critical stock definition cannot be added for a product
                      with StockType 1 (no stock tracking).
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResult'
              example:
                Success: false
                ResultCode: '0102'
                Message: Token has expired. Obtain a new token using the refresh token.
                Errors:
                  - Code: '0102'
                    Message: >-
                      Token has expired. Obtain a new token using the refresh
                      token.
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResult'
              example:
                Success: false
                ResultCode: '0110'
                Message: You do not have permission for this operation.
                Errors:
                  - Code: '0110'
                    Message: You do not have permission for this operation.
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResult'
              example:
                Success: false
                ResultCode: '0120'
                Message: Daily request limit (10000) exceeded.
                Errors:
                  - Code: '0120'
                    Message: Daily request limit (10000) exceeded.
components:
  schemas:
    ProductCriticalStockRequestDto:
      type: object
      properties:
        WarehouseId:
          type:
            - 'null'
            - string
          description: Required. ID of a warehouse from GET /api/v1/stock/warehouses.
          format: uuid
        MinStock:
          type: number
          description: Minimum stock level. Cannot be negative.
          format: double
          example: 10
        MaxStock:
          type: number
          description: >-
            Maximum stock level. Cannot be negative; 0 means no maximum. When
            greater than 0, it cannot be less than MinStock.
          format: double
          example: 500
        MaxStockControl:
          type: integer
          description: >-
            What happens when MaxStock is exceeded. 0: Continue, 1: Warn the
            user, 2: Stop the operation.
          format: int32
          example: 1
        MinStockControl:
          type: integer
          description: >-
            What happens when stock falls below MinStock. 0: Continue, 1: Warn
            the user, 2: Stop the operation.
          format: int32
          example: 1
        NegativeStockControl:
          type: integer
          description: >-
            What happens when stock would go negative. 0: Continue, 1: Warn the
            user, 2: Stop the operation.
          format: int32
          example: 2
    DataResultOfProductCriticalStockDto:
      required:
        - Success
        - ResultCode
        - Data
      type: object
      properties:
        Success:
          type: boolean
          description: Whether the operation succeeded.
          example: true
        ResultCode:
          type: string
          description: >-
            "0000" on success. On failure, the code of the first error; all
            errors are listed in Errors.
          example: '0000'
        Message:
          type:
            - 'null'
            - string
          description: >-
            Error message when Success is false. Messages of all errors are
            joined into a single text.
        Data:
          $ref: '#/components/schemas/ProductCriticalStockDto'
    ErrorResult:
      type: object
      properties:
        Success:
          type: boolean
          description: Whether the operation succeeded.
          example: false
        ResultCode:
          type:
            - 'null'
            - string
          description: >-
            "0000" on success. On failure, the code of the first error; all
            errors are listed in Errors.
        Message:
          type:
            - 'null'
            - string
          description: >-
            Error message when Success is false. Messages of all errors are
            joined into a single text.
        Errors:
          type:
            - 'null'
            - array
          items:
            $ref: '#/components/schemas/ResultError'
          description: All errors with their codes. Only present when Success is false.
    ProductCriticalStockDto:
      type: object
      properties:
        Id:
          type: string
          description: Critical stock definition ID.
          format: uuid
        ProductId:
          type: string
          description: Product ID.
          format: uuid
        WarehouseName:
          type:
            - 'null'
            - string
          description: Warehouse name.
          example: A DEPO
        WarehouseId:
          type:
            - 'null'
            - string
          description: Required. ID of a warehouse from GET /api/v1/stock/warehouses.
          format: uuid
        MinStock:
          type: number
          description: Minimum stock level. Cannot be negative.
          format: double
          example: 10
        MaxStock:
          type: number
          description: >-
            Maximum stock level. Cannot be negative; 0 means no maximum. When
            greater than 0, it cannot be less than MinStock.
          format: double
          example: 500
        MaxStockControl:
          type: integer
          description: >-
            What happens when MaxStock is exceeded. 0: Continue, 1: Warn the
            user, 2: Stop the operation.
          format: int32
          example: 1
        MinStockControl:
          type: integer
          description: >-
            What happens when stock falls below MinStock. 0: Continue, 1: Warn
            the user, 2: Stop the operation.
          format: int32
          example: 1
        NegativeStockControl:
          type: integer
          description: >-
            What happens when stock would go negative. 0: Continue, 1: Warn the
            user, 2: Stop the operation.
          format: int32
          example: 2
    ResultError:
      required:
        - Code
        - Message
      type: object
      properties:
        Code:
          type: string
          description: Error code. See the result codes page for the full list.
        Message:
          type: string
          description: Error description.
  securitySchemes:
    Bearer:
      type: http
      description: Access token obtained from the Noyax auth service with your API key.
      scheme: bearer
      bearerFormat: JWT

````