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 '
{
  "brand": "<string>",
  "name": "<string>",
  "stock": 123,
  "price": 123
}
'
{
  "product": {
    "_id": "<string>",
    "brand": "<string>",
    "name": "<string>",
    "stock": 123,
    "price": 123,
    "normalizedName": "<string>"
  }
}
Updates an existing product’s information.

Authentication

This endpoint requires authentication. Include a valid JWT token in the Authorization header.

Path Parameters

id
string
required
The unique identifier of the product to update

Request Body

All fields are optional. Only include the fields you want to update.
brand
string
The brand or manufacturer of the product
name
string
The name of the product
stock
number
The quantity of items available in stock
price
number
The price of the product

Response

product
object
The updated product object
_id
string
Unique identifier for the product
brand
string
The product brand
name
string
The product name
stock
number
The quantity in stock
price
number
The product price
normalizedName
string
Normalized version of the product name for search purposes

Status Codes

  • 200: Product successfully updated
  • 404: Product not found
  • 401: Authentication token missing or invalid
  • 500: Server error

Example Request

curl -X PUT http://localhost:3000/products/507f1f77bcf86cd799439011 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "stock": 200,
    "price": 24.99
  }'

Example Response

{
  "product": {
    "_id": "507f1f77bcf86cd799439011",
    "brand": "TechCorp",
    "name": "Wireless Mouse",
    "stock": 200,
    "price": 24.99,
    "normalizedName": "wireless mouse"
  }
}

Error Response (404)

{
  "message": "❌ Producto no encontrado para actualizar..."
}

Error Response (500)

{
  "message": "❌ Error en el servidor...",
  "error": "Database update failed"
}

Build docs developers (and LLMs) love