Skip to main content
POST
/
products
Create Product
curl --request POST \
  --url https://api.example.com/products \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "description": "<string>",
  "stock": 123,
  "price": 123,
  "categoriesID": 123
}
'
{
  "error": true,
  "msg": "<string>"
}
This endpoint creates a new product in the system. All fields are required and must meet the validation requirements.

Request Body

name
string
required
Product name. Must be at least 3 characters long.Validation: Minimum length of 3 characters
description
string
required
Product description. Must be between 3 and 3000 characters.Validation: Minimum 3 characters, maximum 3000 characters
stock
integer
required
Available stock quantity. Must be a non-negative integer.Validation: Integer, minimum value of 0
price
integer
required
Product price. Must be a non-negative integer.Validation: Integer, minimum value of 0
categoriesID
integer
required
Category ID to which this product belongs. Must reference an existing category.Validation: Integer, minimum value of 0

Request Example

{
  "name": "Coca cola",
  "description": "Bebida gasificada de 2ltr",
  "stock": 40,
  "price": 3000,
  "categoriesID": 1
}

Response

error
boolean
Indicates if an error occurred during the request
msg
string
Response message describing the result

Success Response (200)

Product created successfully.

Error Responses

400 - Invalid Request

{
  "error": true,
  "msg": "request body is empty"
}
or
{
  "error": true,
  "msg": "information format is incorrect"
}

409 - Conflict

Returned when the product already exists or the category ID is invalid.

Validation Rules

All validation is performed using Zod schemas in products.validation.js:
  • name: String with minimum 3 characters
  • description: String with minimum 3 characters and maximum 3000 characters
  • price: Integer with minimum value 0
  • stock: Integer with minimum value 0
  • categoriesID: Integer with minimum value 0 (must reference existing category)

Build docs developers (and LLMs) love