Skip to main content
POST
/
api
/
products
Create Product
curl --request POST \
  --url https://api.example.com/api/products \
  --header 'Content-Type: application/json' \
  --data '
{
  "nombre": "<string>",
  "descripcion": "<string>",
  "precio": 123,
  "precioOriginal": 123,
  "stock": 123,
  "categoriaId": 123,
  "marcaId": 123,
  "peso": 123,
  "alto": 123,
  "ancho": 123,
  "profundidad": 123,
  "isFeatured": true
}
'
{
  "success": true,
  "data": {
    "id": 123,
    "nombre": "<string>",
    "descripcion": "<string>",
    "precio": 123,
    "precioOriginal": 123,
    "stock": 123,
    "foto": "<string>",
    "isFeatured": true,
    "peso": 123,
    "alto": 123,
    "ancho": 123,
    "profundidad": 123,
    "categoriaId": 123,
    "marcaId": 123,
    "createdAt": {},
    "updatedAt": {}
  }
}

Endpoint

POST /api/products

Authentication

Admin access required. Only users with the ADMIN role can create products.

Request Headers

Content-Type: multipart/form-data
Authorization: Bearer <access_token>

Request Body

This endpoint accepts multipart/form-data to support image upload.
nombre
string
required
Product name (minimum 3 characters)
descripcion
string
required
Product description (minimum 10 characters)
precio
number
required
Product price (must be positive)
precioOriginal
number
Original price (for displaying discounts)
stock
number
required
Initial stock quantity (must be non-negative integer)
categoriaId
number
required
Category ID to associate with this product
marcaId
number
Brand ID to associate with this product
peso
number
default:"0.5"
Product weight in kg
alto
number
default:"10"
Product height in cm
ancho
number
default:"10"
Product width in cm
profundidad
number
default:"10"
Product depth in cm
Whether this product should be featured
foto
file
Product image file (uploaded as multipart form data)

Response

success
boolean
Indicates if the product was created successfully
data
object
The newly created product object
id
number
Unique product identifier
nombre
string
Product name
descripcion
string
Product description
precio
decimal
Product price
precioOriginal
decimal
Original price
stock
number
Stock quantity
foto
string
Uploaded product image URL
Featured status
peso
decimal
Weight in kg
alto
number
Height in cm
ancho
number
Width in cm
profundidad
number
Depth in cm
categoriaId
number
Category ID
marcaId
number
Brand ID
createdAt
datetime
Creation timestamp
updatedAt
datetime
Last update timestamp

Example Request

curl -X POST "https://api.pcfix.com/api/products" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -F "nombre=Gaming Mouse Pro" \
  -F "descripcion=High-precision gaming mouse with RGB lighting and customizable buttons" \
  -F "precio=79.99" \
  -F "stock=50" \
  -F "categoriaId=8" \
  -F "marcaId=3" \
  -F "peso=0.15" \
  -F "alto=5" \
  -F "ancho=8" \
  -F "profundidad=12" \
  -F "isFeatured=true" \
  -F "foto=@/path/to/mouse-image.jpg"

Example Response

{
  "success": true,
  "data": {
    "id": 42,
    "nombre": "Gaming Mouse Pro",
    "descripcion": "High-precision gaming mouse with RGB lighting and customizable buttons",
    "precio": "79.99",
    "precioOriginal": null,
    "stock": 50,
    "foto": "https://cdn.pcfix.com/uploads/mouse-image-1234567890.jpg",
    "isFeatured": true,
    "peso": "0.15",
    "alto": 5,
    "ancho": 8,
    "profundidad": 12,
    "categoriaId": 8,
    "marcaId": 3,
    "createdAt": "2024-03-05T10:30:00Z",
    "updatedAt": "2024-03-05T10:30:00Z"
  }
}

Error Responses

Validation Error

{
  "success": false,
  "error": "Datos inválidos",
  "details": [
    {
      "field": "nombre",
      "message": "El nombre debe tener al menos 3 caracteres"
    },
    {
      "field": "precio",
      "message": "El precio debe ser positivo"
    }
  ]
}

Unauthorized

{
  "success": false,
  "error": "Unauthorized - Admin access required"
}

Server Error

{
  "success": false,
  "error": "Error message description"
}

Build docs developers (and LLMs) love