Skip to main content
POST
/
sales
Create Sale
curl --request POST \
  --url https://api.example.com/sales \
  --header 'Content-Type: application/json' \
  --data '
{
  "clientId": "<string>",
  "ordenDetails": [
    {
      "productId": "<string>",
      "quantity": 123
    }
  ]
}
'
This endpoint creates a sale order by associating a client with one or more products. The system automatically deducts the ordered quantity from the product stock.

Request Body

clientId
string
required
UUID of the client making the purchase
ordenDetails
array
required
Array of products being purchased. Must contain at least one item.

Request Example

{ 
  "clientId": "036c71c5-14e0-11f1-9fcd-2418c6c96a00",
  "ordenDetails": [
    {
      "productId": "1373fe00-14e4-11f1-9fcd-2418c6c96a00",
      "quantity": 10
    }
  ] 
}

Automatic Stock Management

When a sale is created, the system automatically deducts the purchased quantity from the product’s stock. This ensures inventory levels are always accurate and up-to-date.

Stock Deduction Example

When the above sale is created with 10 units of Coca Cola: Before the sale - /products/1373fe00-14e4-11f1-9fcd-2418c6c96a00
{
  "error": false,
  "msg": "Product got sucessfully",
  "product": {
    "id": "b6da7bbc-14b9-11f1-9fcd-2418c6c96a00",
    "name": "Coca cola",
    "description": "Bebida gasificada de 2ltr",
    "price": "3000.00",
    "stock": 40,
    "category_id": 1,
    "created_at": "2026-02-28T15:25:29.000Z",
    "updated_at": "2026-02-28T15:25:29.000Z"
  }
}
After the sale - Stock reduced from 40 to 30
{
  "error": false,
  "msg": "Product got sucessfully",
  "product": {
    "id": "1373fe00-14e4-11f1-9fcd-2418c6c96a00",
    "name": "Coca cola",
    "description": "Bebida gasificada de 2ltr",
    "price": "3000.00",
    "stock": 30,
    "category_id": 1,
    "created_at": "2026-02-28T20:28:43.000Z",
    "updated_at": "2026-02-28T20:31:28.000Z"
  }
}

Error Responses

Insufficient Stock

If the requested quantity exceeds available stock, the API will return an error and the sale will not be created.

Invalid Data

{
  "error": true,
  "msg": "the data is invalid"
}
Returned when:
  • clientId is not a valid UUID
  • ordenDetails is empty or missing
  • productId is not a valid UUID
  • quantity is less than 0

Build docs developers (and LLMs) love