Skip to main content
PATCH
/
sales
/
:id
Update Sale
curl --request PATCH \
  --url https://api.example.com/sales/:id \
  --header 'Content-Type: application/json' \
  --data '
{
  "productId": "<string>",
  "quantity": 123
}
'
This endpoint updates a specific sale detail by modifying the product or quantity. The system automatically adjusts stock levels to reflect the changes.

Path Parameters

id
string
required
UUID of the sale detail to update (use idSalesDetails from GET responses)

Request Body

All fields are optional, but at least one must be provided.
productId
string
UUID of the new product to replace the current one
quantity
integer
New quantity for the product. Must be greater than 0.

Request Example

{
  "productId": "1373fe00-14e4-11f1-9fcd-2418c6c96a00",
  "quantity": 20
}

Stock Adjustment Behavior

When updating a sale detail, the system automatically manages stock levels:

Changing Quantity

  • Increase: Additional units are deducted from stock
  • Decrease: Excess units are returned to stock

Changing Product

  • Original product: Stock is restored by the original quantity
  • New product: Stock is deducted by the specified quantity

Error Responses

Invalid ID

{
  "error": true,
  "msg": "the id is invalid"
}
Returned when the sale detail ID is not a valid UUID.

Empty Request Body

{
  "error": true,
  "msg": "request body is empty"
}
Returned when no update fields are provided.

Invalid Data

{
  "error": true,
  "msg": "the data is invalid"
}
Returned when:
  • productId is provided but not a valid UUID
  • quantity is less than 0
  • The requested quantity exceeds available stock

Important Notes

  • The id parameter refers to the sale detail ID (idSalesDetails), not the sale ID (idSales)
  • Stock adjustments happen automatically and atomically with the update
  • If insufficient stock is available for the new quantity/product, the update will fail

Build docs developers (and LLMs) love