Skip to main content
POST
/
api
/
admin
/
product
Create Product
curl --request POST \
  --url https://api.example.com/api/admin/product \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "description": "<string>",
  "price": 123,
  "stock": 123,
  "categoryId": 123,
  "variant": "<string>",
  "images": [
    null
  ]
}
'
{
  "statusCode": 123,
  "message": "<string>",
  "data": {
    "id": 123,
    "name": "<string>",
    "slug": "<string>",
    "description": "<string>",
    "variant": [
      {}
    ],
    "price": 123,
    "stock": 123,
    "category_id": 123,
    "category_name": "<string>",
    "img_urls": [
      {}
    ],
    "created_at": "<string>"
  }
}

Authentication

This endpoint requires admin authentication. You must be logged in as an admin user.
Authorization
string
required
Bearer token for admin authentication

Request Body

This endpoint accepts multipart/form-data to support file uploads.
name
string
required
Product name
description
string
required
Product description
price
number
required
Product price
stock
integer
required
Available stock quantity
categoryId
integer
required
Category ID to which this product belongs
variant
string
JSON string array of product variants (e.g., ["S", "M", "L", "XL"] or ["Red", "Blue", "Green"])
images
file[]
required
Product images (multiple files supported). At least one image is required. Accepts common image formats (JPEG, PNG, etc.)

Response

statusCode
integer
HTTP status code (201 for success)
message
string
Response message
data
object
The newly created product object

Example Request

curl --request POST \
  --url 'https://api.example.com/api/admin/product' \
  --header 'Authorization: Bearer your_admin_token_here' \
  --header 'Content-Type: multipart/form-data' \
  --form 'name=Premium Leather Jacket' \
  --form 'description=High-quality leather jacket with modern design' \
  --form 'price=199.99' \
  --form 'stock=50' \
  --form 'categoryId=3' \
  --form 'variant=["S","M","L","XL"]' \
  --form 'images=@/path/to/image1.jpg' \
  --form 'images=@/path/to/image2.jpg' \
  --form 'images=@/path/to/image3.jpg'

Example Response

{
  "statusCode": 201,
  "message": "Product added successfully",
  "data": {
    "id": 42,
    "name": "Premium Leather Jacket",
    "slug": "premium-leather-jacket",
    "description": "High-quality leather jacket with modern design",
    "variant": ["S", "M", "L", "XL"],
    "price": 199.99,
    "stock": 50,
    "category_id": 3,
    "category_name": "Outerwear",
    "img_urls": [
      "uploads/products/1234567890-image1.jpg",
      "uploads/products/1234567891-image2.jpg",
      "uploads/products/1234567892-image3.jpg"
    ],
    "created_at": "2026-03-03T10:30:00.000Z"
  }
}

Error Responses

Missing Required Fields

{
  "statusCode": 400,
  "message": "All fields are required"
}

Missing Images

{
  "statusCode": 400,
  "message": "At least one image file is required"
}

Invalid Variant Format

{
  "statusCode": 400,
  "message": "Invalid format for variants. Must be a JSON array."
}

Product Already Exists

{
  "statusCode": 409,
  "message": "Product already exists"
}

Notes

  • The slug is automatically generated from the product name by converting to lowercase, replacing spaces with hyphens, and removing special characters
  • Product names must be unique - you cannot create two products with the same name
  • The variant field should be a JSON string representation of an array
  • Multiple images can be uploaded simultaneously using the images field
  • Image paths are automatically normalized to use forward slashes

Build docs developers (and LLMs) love