Skip to main content
PUT
/
api
/
products
/
:id
Update Product
curl --request PUT \
  --url https://api.example.com/api/products/:id \
  --header 'Content-Type: application/json' \
  --data '
{
  "nombre": "<string>",
  "descripcion": "<string>",
  "precio": 123,
  "precioOriginal": 123,
  "stock": 123,
  "categoriaId": 123,
  "marcaId": 123,
  "peso": 123,
  "alto": 123,
  "ancho": 123,
  "profundidad": 123,
  "isFeatured": true
}
'
{
  "success": true,
  "data": {
    "id": 123,
    "nombre": "<string>",
    "descripcion": "<string>",
    "precio": 123,
    "precioOriginal": 123,
    "stock": 123,
    "foto": "<string>",
    "isFeatured": true,
    "peso": 123,
    "alto": 123,
    "ancho": 123,
    "profundidad": 123,
    "categoriaId": 123,
    "marcaId": 123,
    "createdAt": {},
    "updatedAt": {}
  }
}

Endpoint

PUT /api/products/:id

Authentication

Admin access required. Only users with the ADMIN role can update products.

Path Parameters

id
number
required
The unique identifier of the product to update

Request Headers

Content-Type: multipart/form-data
Authorization: Bearer <access_token>

Request Body

This endpoint accepts multipart/form-data to support image upload. All fields are optional - only include fields you want to update.
nombre
string
Product name (minimum 3 characters)
descripcion
string
Product description (minimum 10 characters)
precio
number
Product price (must be positive)
precioOriginal
number
Original price (for displaying discounts)
stock
number
Stock quantity (must be non-negative integer)
categoriaId
number
Category ID to associate with this product
marcaId
number
Brand ID to associate with this product
peso
number
Product weight in kg
alto
number
Product height in cm
ancho
number
Product width in cm
profundidad
number
Product depth in cm
Whether this product should be featured
foto
file
Product image file (uploaded as multipart form data). If provided, replaces the existing image.

Response

success
boolean
Indicates if the product was updated successfully
data
object
The updated product object
id
number
Unique product identifier
nombre
string
Product name
descripcion
string
Product description
precio
decimal
Product price
precioOriginal
decimal
Original price
stock
number
Stock quantity
foto
string
Product image URL
Featured status
peso
decimal
Weight in kg
alto
number
Height in cm
ancho
number
Width in cm
profundidad
number
Depth in cm
categoriaId
number
Category ID
marcaId
number
Brand ID
createdAt
datetime
Creation timestamp
updatedAt
datetime
Last update timestamp

Example Request

curl -X PUT "https://api.pcfix.com/api/products/42" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -F "precio=69.99" \
  -F "stock=75" \
  -F "isFeatured=false"

Example Response

{
  "success": true,
  "data": {
    "id": 42,
    "nombre": "Gaming Mouse Pro",
    "descripcion": "High-precision gaming mouse with RGB lighting and customizable buttons",
    "precio": "69.99",
    "precioOriginal": "79.99",
    "stock": 75,
    "foto": "https://cdn.pcfix.com/uploads/mouse-image-1234567890.jpg",
    "isFeatured": false,
    "peso": "0.15",
    "alto": 5,
    "ancho": 8,
    "profundidad": 12,
    "categoriaId": 8,
    "marcaId": 3,
    "createdAt": "2024-03-05T10:30:00Z",
    "updatedAt": "2024-03-05T15:45:00Z"
  }
}

Error Responses

Invalid Product ID

{
  "success": false,
  "error": "Product not found"
}

Validation Error

{
  "success": false,
  "error": "Datos inválidos",
  "details": [
    {
      "field": "precio",
      "message": "El precio debe ser positivo"
    }
  ]
}

Unauthorized

{
  "success": false,
  "error": "Unauthorized - Admin access required"
}

Server Error

{
  "success": false,
  "error": "Error message description"
}

Notes

  • Only include fields you want to update in the request body
  • If a new image is uploaded, it will replace the existing image
  • The updatedAt timestamp is automatically updated
  • Product dimensions and weight are important for shipping calculations

Build docs developers (and LLMs) love