Skip to main content

Create Product

Create a new product with image upload support. Requires admin authentication.

Authentication

Requires Clerk authentication with admin role. All admin routes are protected by protectRoute and adminOnly middleware.

Request

Content-Type: multipart/form-data
name
string
required
Product name
description
string
required
Product description
price
number
required
Product price (must be >= 0)
stock
number
required
Available stock quantity (must be >= 0)
category
string
required
Product category
images
file[]
required
Product images (1-3 files). Uploaded to Cloudinary in the products folder.

Response

message
string
Success message
product
object
The created product object
product._id
string
MongoDB ObjectId
product.name
string
Product name
product.description
string
Product description
product.price
number
Product price
product.stock
number
Available stock
product.category
string
Product category
product.images
string[]
Array of Cloudinary image URLs
product.averageRating
number
Average rating (0-5, default: 0)
product.totalReviews
number
Total number of reviews (default: 0)
product.createdAt
string
ISO 8601 timestamp
product.updatedAt
string
ISO 8601 timestamp
curl -X POST https://api.example.com/api/admin/products \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "name=Empanada de Carne" \
  -F "description=Deliciosa empanada rellena de carne" \
  -F "price=5000" \
  -F "stock=100" \
  -F "category=empanadas" \
  -F "images=@image1.jpg" \
  -F "images=@image2.jpg"
{
  "message": "Product created successfully",
  "product": {
    "_id": "507f1f77bcf86cd799439011",
    "name": "Empanada de Carne",
    "description": "Deliciosa empanada rellena de carne",
    "price": 5000,
    "stock": 100,
    "category": "empanadas",
    "images": [
      "https://res.cloudinary.com/.../products/abc123.jpg",
      "https://res.cloudinary.com/.../products/def456.jpg"
    ],
    "averageRating": 0,
    "totalReviews": 0,
    "createdAt": "2026-03-04T10:30:00.000Z",
    "updatedAt": "2026-03-04T10:30:00.000Z"
  }
}

Get All Products

Retrieve all products sorted by creation date (newest first). Requires admin authentication.

Authentication

Requires Clerk authentication with admin role.

Response

products
array
Array of product objects sorted by createdAt descending
curl -X GET https://api.example.com/api/admin/products \
  -H "Authorization: Bearer YOUR_TOKEN"
[
  {
    "_id": "507f1f77bcf86cd799439011",
    "name": "Empanada de Carne",
    "description": "Deliciosa empanada rellena de carne",
    "price": 5000,
    "stock": 100,
    "category": "empanadas",
    "images": [
      "https://res.cloudinary.com/.../products/abc123.jpg"
    ],
    "averageRating": 4.5,
    "totalReviews": 23,
    "createdAt": "2026-03-04T10:30:00.000Z",
    "updatedAt": "2026-03-04T10:30:00.000Z"
  }
]

Update Product

Update an existing product. All fields are optional. Supports image upload.

Authentication

Requires Clerk authentication with admin role.

Path Parameters

id
string
required
MongoDB ObjectId of the product to update

Request

Content-Type: multipart/form-data
name
string
Updated product name
description
string
Updated product description
price
number
Updated product price
stock
number
Updated stock quantity
category
string
Updated product category
images
file[]
New product images (1-3 files). If provided, replaces all existing images.

Response

message
string
Success message
product
object
The updated product object
curl -X PUT https://api.example.com/api/admin/products/507f1f77bcf86cd799439011 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -F "price=6000" \
  -F "stock=150"
{
  "message": "Product updated successfully",
  "product": {
    "_id": "507f1f77bcf86cd799439011",
    "name": "Empanada de Carne",
    "description": "Deliciosa empanada rellena de carne",
    "price": 6000,
    "stock": 150,
    "category": "empanadas",
    "images": [
      "https://res.cloudinary.com/.../products/abc123.jpg"
    ],
    "averageRating": 4.5,
    "totalReviews": 23,
    "createdAt": "2026-03-04T10:30:00.000Z",
    "updatedAt": "2026-03-04T12:15:00.000Z"
  }
}

Delete Product

Delete a product and remove its images from Cloudinary.

Authentication

Requires Clerk authentication with admin role.

Path Parameters

id
string
required
MongoDB ObjectId of the product to delete

Response

message
string
Success message
curl -X DELETE https://api.example.com/api/admin/products/507f1f77bcf86cd799439011 \
  -H "Authorization: Bearer YOUR_TOKEN"
{
  "message": "Product deleted successfully"
}

Build docs developers (and LLMs) love