Overview
This endpoint allows administrators to update an existing product in the catalog. All fields are optional, and you can optionally upload a new image.
Endpoint
Path Parameters
The unique identifier of the product to update
Authentication
Required: Admin role
This endpoint requires a valid JWT token with admin privileges. Include the token in the Authorization header:
Authorization: Bearer <your_token>
Request Body
This endpoint accepts multipart/form-data format if uploading a new image, or application/json for other updates.
Product price (maximum 2 decimal places)
Product image URL (can be set directly)
ID of the category this product belongs to (must be >= 1 if provided)
New product image file (uploaded as multipart/form-data with field name ‘image’)
Validation Rules
name: If provided, must be a valid string
description: If provided, must be a valid string
price: If provided, must be a number with maximum 2 decimal places
categoryId: If provided, must be an integer >= 1
image: Optional file field - if provided, will replace the existing image
Response
Returns the updated product object.
Unique identifier for the product
Product price (decimal with 2 decimal places)
ID of the category this product belongs to
Timestamp when the product was created
Timestamp when the product was last updated
Example Request (JSON)
curl -X PUT https://api.example.com/products/1 \
-H "Authorization: Bearer <your_admin_token>" \
-H "Content-Type: application/json" \
-d '{
"name": "Premium Laptop",
"price": 1499.99
}'
Example Request (With Image Upload)
curl -X PUT https://api.example.com/products/1 \
-H "Authorization: Bearer <your_admin_token>" \
-F "name=Premium Laptop" \
-F "price=1499.99" \
-F "image=@/path/to/new-laptop.jpg"
Example Response
{
"id": 1,
"name": "Premium Laptop",
"description": "High-performance laptop for professionals",
"price": "1499.99",
"imageUrl": "https://example.com/uploads/laptop-updated-1234567890.jpg",
"stock": 15,
"categoryId": 2,
"createdAt": "2026-01-15T10:30:00.000Z",
"updatedAt": "2026-03-06T14:25:00.000Z"
}
Status Code: 200 OK
Error Responses
Product Not Found
{
"error": "Product not found"
}
Status Code: 404 Not Found
Validation Error
{
"error": "Validation failed",
"details": [
{
"field": "price",
"message": "El precio debe ser un número válido con máximo 2 decimales"
}
]
}
Status Code: 400 Bad Request
Unauthorized
{
"error": "Unauthorized"
}
Status Code: 401 Unauthorized
Forbidden (Non-Admin User)
{
"error": "Admin access required"
}
Status Code: 403 Forbidden
Invalid Category ID
{
"error": "Validation failed",
"details": [
{
"field": "categoryId",
"message": "Debe proporcionar un ID de categoría válido"
}
]
}
Status Code: 400 Bad Request