Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/astrxnomo/shop-microservers/llms.txt

Use this file to discover all available pages before exploring further.

This endpoint reduces a product’s stock count by the supplied decrement value and returns the updated product record. It is designed to be called by the orders service as part of the checkout flow — after a successful order is created, the orders service calls this endpoint for each line item to commit the inventory change in the catalog database.
This endpoint is intended for internal use by the orders service. Calling it directly will permanently reduce the product’s stock without creating a corresponding order record. There is no built-in undo — ensure you only call this endpoint as part of a coordinated checkout transaction.

Endpoint

PATCH /api/catalog/products/:id/stock
No token-based authentication is enforced on this route. Access control relies on the internal Docker network — this endpoint is not intended to be reachable from outside the service mesh.

Request

Path parameters

id
string
required
The CUID of the product whose stock should be decremented.

Request body

decrement
number
required
A positive integer representing the quantity to subtract from the product’s current stock. Must be a whole number greater than zero. Validated against StockDecrementSchema (z.number().int().positive()).

Example request

curl -X PATCH http://localhost/api/catalog/products/clxxxxxxxxxxxxx/stock \
  -H "Content-Type: application/json" \
  -d '{"decrement": 2}'

Response

200 — Success

Returns the full updated product object after the stock decrement has been applied.
{
  "success": true,
  "data": {
    "id": "clxxxxxxxxxxxxx",
    "name": "Wireless Headphones",
    "price": 79.99,
    "imageUrl": "https://example.com/headphones.jpg",
    "stock": 48,
    "category": "Electronics",
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-01-15T10:35:00.000Z"
  },
  "error": null
}

400 — Validation Error

Returned when the request body fails schema validation — for example, if decrement is missing, is not an integer, or is zero or negative.
{
  "success": false,
  "data": null,
  "error": "..."
}

404 — Product Not Found

Returned when no product with the given id exists in the catalog database.
{
  "success": false,
  "data": null,
  "error": "Product not found"
}

409 — Insufficient Stock

Returned when the requested decrement value exceeds the product’s current stock count. The stock will not be modified.
{
  "success": false,
  "data": null,
  "error": "Insufficient stock"
}

Build docs developers (and LLMs) love