Skip to main content

PATCH /api/products/:id

Updates an existing product in the system. All fields are optional - only provided fields will be updated.

Authentication

Required. Must include a valid JWT token in the Authorization header.

Authorization

Admin role required.

Request Headers

Authorization: Bearer <jwt_token>
Content-Type: application/json

Path Parameters

id
string
required
The unique identifier of the product to update

Body Parameters

All body parameters are optional. Only include the fields you want to update.
name
string
Product name
description
string
Product description
price
number
Product price
stock
number
Available stock quantity
category
string
Product category. Must be one of: digital, physical, service
image
string
Image URL for the product
isActive
boolean
Whether the product is active

Response

message
string
Success message
product
object
The updated product object
_id
string
Unique product identifier
name
string
Product name
description
string
Product description
price
number
Product price
stock
number
Available stock quantity
category
string
Product category
image
string
Image URL for the product
createdBy
string
ID of the admin user who created the product
isActive
boolean
Whether the product is active
createdAt
string
ISO 8601 timestamp of creation
updatedAt
string
ISO 8601 timestamp of last update (automatically updated)

Example Request

curl -X PATCH https://api.example.com/api/products/507f1f77bcf86cd799439011 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "price": 89.99,
    "stock": 150
  }'

Example Response

{
  "message": "Product updated successfully",
  "product": {
    "_id": "507f1f77bcf86cd799439011",
    "name": "Bitcoin Mining Course",
    "description": "Learn how to mine Bitcoin from scratch",
    "price": 89.99,
    "stock": 150,
    "category": "digital",
    "image": "https://example.com/images/bitcoin-course.jpg",
    "createdBy": "507f1f77bcf86cd799439000",
    "isActive": true,
    "createdAt": "2026-03-04T10:30:00.000Z",
    "updatedAt": "2026-03-04T14:45:00.000Z"
  }
}

Error Responses

404 - Not Found

{
  "error": "Product not found"
}

401 - Unauthorized

{
  "error": "Authentication required"
}

403 - Forbidden

{
  "error": "Admin access required"
}

500 - Internal Server Error

{
  "error": "Database connection failed"
}

Build docs developers (and LLMs) love