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 upload image endpoint replaces a product’s image. You provide the image as a base64 data URI or a publicly accessible URL in the JSON request body. The value is passed to Cloudinary, which stores it in the products/ folder using the product’s slug as the public ID — so re-uploading always overwrites the previous image. Cloudinary automatically resizes the image to 500×500 pixels, crops to fill, and selects the optimal format and quality. The resulting Cloudinary URL is then persisted to product.image. Only administrators may call this endpoint.

Endpoint

PUT /api/v1/products/:id/image
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 whose image should be updated (e.g. 64f1c2e9a1b2c3d4e5f12345).

Request body

image
string
required
The image source to upload. Accepted values:
  • A publicly accessible image URL (e.g. "https://example.com/image.jpg")
  • A base64-encoded data URI (e.g. "data:image/jpeg;base64,/9j/4AAQSk...")

Cloudinary processing

Once received, the image is uploaded to Cloudinary with the following transformations applied automatically:
  • Crop: fill at 500×500 px with auto gravity
  • Format: auto-selected for best browser compatibility
  • Quality: auto-optimised by Cloudinary
The secure_url returned by Cloudinary is saved to product.image.

Response

200 OK
message
string
A human-readable confirmation, e.g. "Image uploaded successfully".
imageUrl
string
The Cloudinary secure_url of the uploaded image now stored on the product.

Error codes

StatusMeaning
400Invalid ID format, or the image field was missing from the request body.
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.
500Internal server error — an unexpected error occurred, including Cloudinary upload failures.

Example

curl https://api.example.com/api/v1/products/64f1c2e9a1b2c3d4e5f12345/image \
  --request PUT \
  --header "Authorization: Bearer <ADMIN_JWT>" \
  --header "Content-Type: application/json" \
  --data '{"image": "https://example.com/matcha-latte.jpg"}'
200 response:
{
  "message": "Image uploaded successfully",
  "imageUrl": "https://res.cloudinary.com/example/image/upload/f_auto,q_auto/v1/products/matcha-latte.jpg"
}
400 response (missing image field):
{
  "message": "Image is required"
}

Build docs developers (and LLMs) love