Skip to main content
POST
/
products
curl -X POST https://api.example.com/products \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Espresso Coffee",
    "price": 12.99,
    "image": "espresso.jpg",
    "inventory": 50,
    "categoryId": 1
  }'
{
  "id": 123,
  "name": "Espresso Coffee",
  "price": 12.99,
  "image": "espresso.jpg",
  "inventory": 50,
  "categoryId": 1,
  "category": {
    "id": 1,
    "name": "Beverages",
    "image": "beverages.jpg"
  }
}
Create a new product in the system.

Authentication

This endpoint requires authentication with the admin role.

Request Body

name
string
required
The product name (max 60 characters)
price
number
required
The product price (max 2 decimal places)
image
string
required
The product image URL or filename
inventory
number
required
The quantity in stock (integer)
categoryId
integer
required
The ID of the category this product belongs to

Response

id
integer
The unique identifier for the product
name
string
The product name
price
number
The product price
image
string
The product image URL or filename
inventory
number
The quantity in stock
categoryId
integer
The category ID
category
object
The category object with full details
curl -X POST https://api.example.com/products \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Espresso Coffee",
    "price": 12.99,
    "image": "espresso.jpg",
    "inventory": 50,
    "categoryId": 1
  }'
{
  "id": 123,
  "name": "Espresso Coffee",
  "price": 12.99,
  "image": "espresso.jpg",
  "inventory": 50,
  "categoryId": 1,
  "category": {
    "id": 1,
    "name": "Beverages",
    "image": "beverages.jpg"
  }
}

Errors

statusCode
integer
HTTP status code
message
array
Array of error messages
{
  "statusCode": 404,
  "message": ["Category not found"]
}

Build docs developers (and LLMs) love