Skip to content

ProductVariantStockUpdateView API Documentation

The ProductVariantStockUpdateView is responsible for handling the restocking of product variants. Vendors or users with the necessary permissions can update the stock quantity of product variants. This view supports partial updates (PATCH).

Endpoint

PATCH /api/v1/catalog/vendor/product-variants/restock/<str:product_id>/

Parameters

  • product_id (path parameter):
  • Description: The unique ID of the product whose variants are being restocked.
  • Type: Integer
  • Required: Yes

  • variants (request body):

  • Description: A list of variant data containing the variant IDs and quantities to be restocked.
  • Type: Array of Objects
  • Required: Yes
  • Fields:
    • id (integer): The ID of the product variant.
    • quantity (integer): The quantity to add to the current stock of the product variant.

Request Body Example

{
  "variants": [
    {
      "id": 1,
      "quantity": 50
    },
    {
      "id": 2,
      "quantity": 30
    }
  ]
}

Responses

Success Response

  • Status Code: 200 OK
  • Description: Returns a success message along with the updated variants and their stock quantities.
  • Response Body:
      {
      "message": "Variants updated successfully.",
      "variants": [
          {
          "variant_id": 1,
          "stock_quantity": 150,
          "is_available": true
          },
          {
          "variant_id": 2,
          "stock_quantity": 80,
          "is_available": true
          }
          ]
      }
    

Error Responses

  • Product Not Found:
    • Status Code: 404 Not Found
    • Description: The product with the given product_id does not exist.
    • Response Body:
          {
          "error": "Product not found."
          }
      
  • Forbidden: Only Vendors or Vendor Roles Can Restock Products

    • Status Code: 403 Forbidden
    • Description: The user does not have the necessary role to restock the product (user role).
    • Response Body:
          {
          "error": "Only vendors or Vendor Roles can restock products."
          }
      
  • Variant Not Found:

    • Status Code: 404 Not Found
    • Description: The variant with the given variant_id does not exist for the specified product.
    • Response Body:
          {
          "error": "Variant with ID {variant_id} does not exist for this product."
          }
      
  • Forbidden: Not Your Product

    • Status Code: 403 Forbidden
    • Description: The vendor is not authorized to restock the product because it doesn't belong to them.
    • Response Body:
          {
          "error": "You can only restock your own products."
          }
      
  • Bad Request: Missing Quantity

    • Status Code: 400 Bad Request
    • Description: The quantity field is required for each variant.
    • Response Body:
          {
          "error": "Quantity must be provided."
          }
      
  • Bad Request: No Variants Provided
    • Status Code: 400 Bad Request
    • Description: No variant data was provided for the restock operation.
    • Response Body:
          {
          "error": "No variants provided for update."
          }