The Ocha API provides a dedicated endpoint for uploading or replacing a product’s image. You send the image as a base64-encoded string or a public URL in a JSON request body. The value is passed directly to Cloudinary, which resizes and optimises it, and the resulting secure URL is saved to the product’sDocumentation 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.
image field. Only administrators can use this endpoint.
Endpoint
| Detail | Value |
|---|---|
| Method | PUT |
| Authentication | Required — Bearer JWT (admin role) |
| Content-Type | application/json |
| Body field name | image |
How it works
Authenticate as an admin
Obtain a JWT token by logging in with an admin account via
POST /api/v1/auth/login. Include the token as a Bearer token in the Authorization header of the upload request.Prepare your image source
The
image field accepts any value that Cloudinary’s uploader accepts — a base64 data URI (e.g. data:image/jpeg;base64,...) or a publicly accessible image URL. Common formats such as JPEG and PNG are accepted. Cloudinary will resize it to 500×500 with fill cropping and auto gravity.Send the JSON request
Send a
PUT request with Content-Type: application/json and a body containing the image field.curl example
Success response
Cloudinary processing
When an image is uploaded, Cloudinary applies the following transformations before storing it:| Setting | Value |
|---|---|
| Width | 500 px |
| Height | 500 px |
| Crop mode | fill |
| Gravity | auto |
| Format | auto (served as WebP where supported) |
| Quality | auto |
| Folder | products/ |
| Public ID | Product’s slug |
| Overwrite | true |
Uploading a new image for a product that already has one will overwrite the existing Cloudinary asset because the public ID is derived from the product’s
slug and overwrite is set to true.Error responses
| Status | Meaning |
|---|---|
400 | The image field is missing from the request body, or the ID format is invalid |
401 | No token provided, the token is invalid, or it has expired |
403 | The authenticated user does not have the admin role |
404 | No product exists with the given :id |
500 | An unexpected server or Cloudinary error occurred |
Next steps
Create a product
Create a product before uploading its image.
Upload image API reference
Full API reference for the image upload endpoint.
Roles and permissions
Learn about admin-only endpoints and how authentication works.
Environment variables
Configure
CLOUDINARY_URL and other required environment variables.