# Update Product Stock

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /v1/products/stock:
    put:
      summary: Update Product Stock
      deprecated: false
      description: >-
        อัพเดทจำนวนสินค้าในระบบ

        **สามารถอัพเดท product ที่ inactive ได้


        รายละเอียด error ที่สามารถพบได้


        - ไม่พบ product code นี้ในระบบ (product code not found)

        - กรุณากรอก product code (require product code)<p><b>สูตร (ทุก endpoint
        ของ Open API)</b><br>AvailableQty = Qty − AllocatedQty
        (ติดลบได้เมื่อจองเกินจำนวนคงเหลือ)<br>ShortfallQty = max(AllocatedQty −
        Qty, 0)<br>ฟิลด์ที่มีค่าเป็น 0 อาจไม่ถูกส่งมาใน response ให้ถือว่าเป็น
        0</p><p>หลังอัปเดตสำเร็จ ระบบส่ง webhook product.edit
        พร้อมสต็อกแยกตามคลังหลังเปลี่ยน</p>
      tags:
        - Venio/Product
        - Venio/Product
      parameters:
        - name: Content-Type
          in: header
          description: ''
          required: false
          example: application/json
          schema:
            type: string
        - name: Ocp-Apim-Subscription-Key
          in: header
          description: ''
          required: false
          example: <Your Subscription-Key>
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: array
              items:
                type: object
                properties:
                  productCode:
                    type: string
                    x-apidog-mock: PD001
                    description: รหัสของ Product
                  warehouses:
                    type: object
                    properties:
                      warehouseCode:
                        type: string
                        x-apidog-mock: WH001
                        description: รหัสของ Warehouse
                      qty:
                        type: number
                        description: qty ของ Product แยกตาม Warehouse
                        x-apidog-mock: '50'
                        nullable: true
                      availableQty:
                        type: number
                        description: availableQty ของ Product แยกตาม Warehouse
                        nullable: true
                      lowStockAlert:
                        type: number
                        x-apidog-mock: '5'
                        description: แจ้งเตือนเมื่อ qty เหลือ
                    x-apidog-orders:
                      - warehouseCode
                      - qty
                      - availableQty
                      - lowStockAlert
                    required:
                      - warehouseCode
                      - lowStockAlert
                    x-apidog-ignore-properties: []
                required:
                  - productCode
                  - warehouses
                x-apidog-orders:
                  - productCode
                  - warehouses
                x-apidog-ignore-properties: []
            example:
              - productCode: PD001
                warehouses:
                  - warehouseCode: WH001
                    qty: 50
                    availableQty: 3
                    lowStockAlert: 5
                  - warehouseCode: WH002
                    qty: 30
                    lowStockAlert: 3
      responses:
        '200':
          x-apidog-name: Success
          x-apidog-ordering: 0
          description: ''
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        productCode:
                          type: string
                          description: product code ในระบบ venio
                        warehouses:
                          type: object
                          properties:
                            warehouseCode:
                              type: string
                              description: รหัสคลังสินค้า
                            qty:
                              type: string
                              description: qty ของ Product แยกตาม Warehouse
                            allocatedQty:
                              type: string
                              description: จำนวนสินค้าที่ติดจอง
                            availableQty:
                              type: string
                              description: >-
                                พร้อมขาย = Qty − AllocatedQty ติดลบได้
                                (ความหมายเดียวกับ GET v2/products)
                            shortfallQty:
                              type: number
                              description: จองเกินคงเหลือ = max(AllocatedQty − Qty, 0)
                            lowStockAlert:
                              type: string
                              description: แจ้งเตือนเมื่อ qty เหลือ
                            isSuccess:
                              type: boolean
                              description: สถานะการอัพเดทข้อมูล
                          x-apidog-orders:
                            - warehouseCode
                            - qty
                            - allocatedQty
                            - availableQty
                            - shortfallQty
                            - lowStockAlert
                            - isSuccess
                          required:
                            - warehouseCode
                            - qty
                            - allocatedQty
                            - availableQty
                            - lowStockAlert
                            - isSuccess
                          description: ข้อมูลสินค้าแยกตาม warehouse
                          x-apidog-ignore-properties: []
                        isSuccess:
                          type: boolean
                          description: สถานะการอัพเดทจำนวนสินค้าของ product code
                        error:
                          type: object
                          properties:
                            description:
                              type: string
                              description: รายละเอียดข้อมูลที่ผิดพลาดของ product code
                          required:
                            - description
                          x-apidog-orders:
                            - description
                          description: ข้อมูลที่ผิดพลาดเมื่อ isSuccess = false
                          x-apidog-ignore-properties: []
                      required:
                        - productCode
                        - warehouses
                        - isSuccess
                        - error
                      x-apidog-orders:
                        - productCode
                        - warehouses
                        - isSuccess
                        - error
                      x-apidog-ignore-properties: []
                  statusCode:
                    type: integer
                    description: สถานะการทำงานของระบบ
                  httpStatusCode:
                    type: integer
                required:
                  - data
                  - statusCode
                  - httpStatusCode
                x-apidog-orders:
                  - data
                  - statusCode
                  - httpStatusCode
                x-apidog-ignore-properties: []
              examples:
                '1':
                  summary: Success
                  value:
                    data:
                      - productCode: PD001
                        warehouses:
                          - warehouseCode: WH001
                            qty: 50
                            availableQty: 49
                            allocatedQty: 1
                            lowStockAlert: 5
                          - warehouseCode: WH002
                            qty: 30
                            availableQty: 49
                            allocatedQty: 1
                            lowStockAlert: 3
                    statusCode: 1000
                    httpStatusCode: 200
                '2':
                  summary: Success
                  value:
                    hasError: true
                    errorMessage: Empty Payload
                    statusCode: 1102
                    httpStatusCode: 400
          headers: {}
        '400':
          description: ''
          content:
            application/json:
              schema:
                title: ''
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/Required%20authorization'
                  status:
                    $ref: '#/components/schemas/Response%20Error%20Msg%20'
                required:
                  - data
                  - status
                x-apidog-orders:
                  - data
                  - status
                x-apidog-ignore-properties: []
          headers: {}
          x-apidog-name: Bad Request
        x-200:OK:
          statusCode: 200
          x-apidog-ordering: 2
          description: ''
          content:
            application/json:
              schema:
                title: ''
                type: object
                properties:
                  data:
                    type: object
                    properties:
                      subCode:
                        type: string
                        x-apidog-mock: E9103
                      description:
                        type: string
                        x-apidog-mock: Authorization credentials required
                      metadata:
                        type: object
                        properties: {}
                        x-apidog-orders: []
                        x-apidog-ignore-properties: []
                    required:
                      - subCode
                      - description
                      - metadata
                    x-apidog-orders:
                      - subCode
                      - description
                      - metadata
                    x-apidog-folder: ''
                    x-apidog-ignore-properties: []
                  status:
                    type: object
                    properties:
                      code:
                        type: string
                        x-apidog-mock: '4001'
                      description:
                        type: string
                        x-apidog-mock: Business error with 1 errors
                    required:
                      - code
                      - description
                    x-apidog-orders:
                      - code
                      - description
                    x-apidog-folder: ''
                    x-apidog-ignore-properties: []
                required:
                  - data
                  - status
                x-apidog-orders:
                  - data
                  - status
                x-apidog-ignore-properties: []
          headers: {}
          x-apidog-name: OK
      security:
        - bearer: []
      x-apidog-folder: Venio/Product
      x-apidog-status: developing
      x-run-in-apidog: https://app.apidog.com/web/project/351895/apis/api-9077337-run
components:
  schemas:
    'Response Error Msg ':
      type: object
      properties:
        code:
          type: string
          x-apidog-mock: '4001'
        description:
          type: string
          x-apidog-mock: Business error with 1 errors
      required:
        - code
        - description
      x-apidog-orders:
        - code
        - description
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
    Required authorization:
      type: object
      properties:
        subCode:
          type: string
          x-apidog-mock: E9103
        description:
          type: string
          x-apidog-mock: Authorization credentials required
        metadata:
          type: object
          properties: {}
          x-apidog-orders: []
          x-apidog-ignore-properties: []
      required:
        - subCode
        - description
        - metadata
      x-apidog-orders:
        - subCode
        - description
        - metadata
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
  securitySchemes:
    bearerAuth:
      type: jwt
      scheme: bearer
      bearerFormat: JWT
      description: ใส่ JWT Token ในรูปแบบ Bearer {token}
    bearer:
      type: http
      scheme: bearer
servers:
  - url: https://api.gofive.co.th
    description: Production
security: []

```
