Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/floriansalvi/HEIG-VD_Ocha-api/llms.txt

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

The update product endpoint allows administrators to modify any combination of fields on an existing product. Only the fields present in the request body are changed — omitted fields retain their current values. If you need to rename a product, bear in mind that both name and slug must remain unique across the catalogue; a 409 is returned if either value conflicts with an existing product.

Endpoint

PATCH /api/v1/products/:id
This endpoint requires an admin JWT. Requests without a valid token or without admin privileges are rejected with 401 or 403 respectively.

Request headers

Authorization
string
required
Bearer token for authentication, e.g. Bearer <JWT>.
Content-Type
string
required
Must be application/json.

Path parameters

id
string
required
The MongoDB ObjectId of the product to update (e.g. 64f1c2e9a1b2c3d4e5f12345).

Request body

All body fields are optional. Supply only the fields you want to change.
slug
string
New URL-friendly identifier. Must be unique across all products.
name
string
New display name. Must be unique across all products.
category
string
New category for the product.
description
string
New description text.
basePriceCHF
number
New base price in CHF. Must be 0 or greater.
isActive
boolean
Set to false to deactivate the product, or true to reactivate it.
image
string
New image URL for the product.
size
string[]
Replacement size array. Each element must be one of "S", "M", or "L".
extra_chf
object
Replacement price surcharges. Replaces the entire extra_chf object.

Response

200 OK
message
string
A human-readable confirmation, e.g. "Product updated".
product
object
The full updated product document reflecting all changes.

Error codes

StatusMeaning
400Invalid ID format — the supplied id is not a valid MongoDB ObjectId.
401Unauthorized — no token or an invalid token was supplied.
403Forbidden — the authenticated user does not have admin privileges.
404Product not found — no product exists with the given id.
409Conflict — the new name or slug is already in use by another product.
422Unprocessable entity — the request body failed schema validation.
500Internal server error — an unexpected error occurred.

Example

Request:
curl https://api.example.com/api/v1/products/64f1c2e9a1b2c3d4e5f12345 \
  --request PATCH \
  --header "Authorization: Bearer <ADMIN_JWT>" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "Caramel Matcha Latte",
    "basePriceCHF": 6.50,
    "description": "Matcha latte with a rich caramel syrup."
  }'
200 response:
{
  "message": "Product updated",
  "product": {
    "_id": "64f1c2e9a1b2c3d4e5f12345",
    "slug": "matcha-latte",
    "name": "Caramel Matcha Latte",
    "category": "Hot drinks",
    "description": "Matcha latte with a rich caramel syrup.",
    "basePriceCHF": 6.50,
    "isActive": true,
    "image": "https://res.cloudinary.com/example/image/upload/products/matcha-latte.jpg",
    "size": ["S", "M", "L"],
    "extra_chf": { "S": 0, "M": 2, "L": 3 },
    "createdAt": "2024-01-15T10:30:00.000Z",
    "updatedAt": "2024-04-01T09:15:00.000Z"
  }
}

Build docs developers (and LLMs) love