Skip to main content
POST
/
products
Create Product
curl --request POST \
  --url https://api.example.com/products \
  --header 'Content-Type: application/json' \
  --data '
{
  "brand": "<string>",
  "name": "<string>",
  "stock": 123,
  "price": 123
}
'
{
  "message": "<string>",
  "product": {
    "_id": "<string>",
    "brand": "<string>",
    "name": "<string>",
    "stock": 123,
    "price": 123,
    "normalizedName": "<string>"
  }
}
Creates a new product in the inventory system.

Authentication

This endpoint requires authentication. Include a valid JWT token in the Authorization header.

Request Body

brand
string
required
The brand or manufacturer of the product
name
string
required
The name of the product
stock
number
required
The quantity of items available in stock
price
number
required
The price of the product

Response

message
string
Success message confirming the product was created
product
object
The created product object
_id
string
Unique identifier for the product
brand
string
The product brand
name
string
The product name
stock
number
The quantity in stock
price
number
The product price
normalizedName
string
Normalized version of the product name for search purposes

Status Codes

  • 200: Product successfully created
  • 400: Invalid request data or validation error
  • 401: Authentication token missing or invalid

Example Request

curl -X POST http://localhost:3000/products \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "brand": "TechCorp",
    "name": "Wireless Mouse",
    "stock": 150,
    "price": 29.99
  }'

Example Response

{
  "message": "✅ Producto nuevo agregado con exito",
  "product": {
    "_id": "507f1f77bcf86cd799439011",
    "brand": "TechCorp",
    "name": "Wireless Mouse",
    "stock": 150,
    "price": 29.99,
    "normalizedName": "wireless mouse"
  }
}

Error Response

{
  "message": "No se pudo guardar el producto: validation error"
}