Skip to main content
PUT
/
products
/
:id
Update Product
curl --request PUT \
  --url https://api.example.com/products/:id \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "description": "<string>",
  "price": 123,
  "imageUrl": "<string>",
  "categoryId": 123
}
'
{
  "id": 123,
  "name": "<string>",
  "description": "<string>",
  "price": 123,
  "imageUrl": "<string>",
  "stock": 123,
  "categoryId": 123,
  "createdAt": {},
  "updatedAt": {}
}

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

PUT /products/:id

Path Parameters

id
integer
required
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.
name
string
Product name
description
string
Product description
price
number
Product price (maximum 2 decimal places)
imageUrl
string
Product image URL (can be set directly)
categoryId
integer
ID of the category this product belongs to (must be >= 1 if provided)
image
file
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.
id
integer
Unique identifier for the product
name
string
Product name
description
string
Product description
price
decimal
Product price (decimal with 2 decimal places)
imageUrl
string
URL to the product image
stock
integer
Available stock quantity
categoryId
integer
ID of the category this product belongs to
createdAt
datetime
Timestamp when the product was created
updatedAt
datetime
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

Build docs developers (and LLMs) love