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
}
'import requests
url = "https://api.example.com/api/products"
payload = {
"nombre": "<string>",
"descripcion": "<string>",
"precio": 123,
"precioOriginal": 123,
"stock": 123,
"categoriaId": 123,
"marcaId": 123,
"peso": 123,
"alto": 123,
"ancho": 123,
"profundidad": 123,
"isFeatured": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
nombre: '<string>',
descripcion: '<string>',
precio: 123,
precioOriginal: 123,
stock: 123,
categoriaId: 123,
marcaId: 123,
peso: 123,
alto: 123,
ancho: 123,
profundidad: 123,
isFeatured: true
})
};
fetch('https://api.example.com/api/products', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/products",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'nombre' => '<string>',
'descripcion' => '<string>',
'precio' => 123,
'precioOriginal' => 123,
'stock' => 123,
'categoriaId' => 123,
'marcaId' => 123,
'peso' => 123,
'alto' => 123,
'ancho' => 123,
'profundidad' => 123,
'isFeatured' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/products"
payload := strings.NewReader("{\n \"nombre\": \"<string>\",\n \"descripcion\": \"<string>\",\n \"precio\": 123,\n \"precioOriginal\": 123,\n \"stock\": 123,\n \"categoriaId\": 123,\n \"marcaId\": 123,\n \"peso\": 123,\n \"alto\": 123,\n \"ancho\": 123,\n \"profundidad\": 123,\n \"isFeatured\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/products")
.header("Content-Type", "application/json")
.body("{\n \"nombre\": \"<string>\",\n \"descripcion\": \"<string>\",\n \"precio\": 123,\n \"precioOriginal\": 123,\n \"stock\": 123,\n \"categoriaId\": 123,\n \"marcaId\": 123,\n \"peso\": 123,\n \"alto\": 123,\n \"ancho\": 123,\n \"profundidad\": 123,\n \"isFeatured\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/products")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"nombre\": \"<string>\",\n \"descripcion\": \"<string>\",\n \"precio\": 123,\n \"precioOriginal\": 123,\n \"stock\": 123,\n \"categoriaId\": 123,\n \"marcaId\": 123,\n \"peso\": 123,\n \"alto\": 123,\n \"ancho\": 123,\n \"profundidad\": 123,\n \"isFeatured\": true\n}"
response = http.request(request)
puts response.read_body{
"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": {}
}
}Products
Create Product
Create a new product in the catalog
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
}
'import requests
url = "https://api.example.com/api/products"
payload = {
"nombre": "<string>",
"descripcion": "<string>",
"precio": 123,
"precioOriginal": 123,
"stock": 123,
"categoriaId": 123,
"marcaId": 123,
"peso": 123,
"alto": 123,
"ancho": 123,
"profundidad": 123,
"isFeatured": True
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
nombre: '<string>',
descripcion: '<string>',
precio: 123,
precioOriginal: 123,
stock: 123,
categoriaId: 123,
marcaId: 123,
peso: 123,
alto: 123,
ancho: 123,
profundidad: 123,
isFeatured: true
})
};
fetch('https://api.example.com/api/products', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/products",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'nombre' => '<string>',
'descripcion' => '<string>',
'precio' => 123,
'precioOriginal' => 123,
'stock' => 123,
'categoriaId' => 123,
'marcaId' => 123,
'peso' => 123,
'alto' => 123,
'ancho' => 123,
'profundidad' => 123,
'isFeatured' => true
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/products"
payload := strings.NewReader("{\n \"nombre\": \"<string>\",\n \"descripcion\": \"<string>\",\n \"precio\": 123,\n \"precioOriginal\": 123,\n \"stock\": 123,\n \"categoriaId\": 123,\n \"marcaId\": 123,\n \"peso\": 123,\n \"alto\": 123,\n \"ancho\": 123,\n \"profundidad\": 123,\n \"isFeatured\": true\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.example.com/api/products")
.header("Content-Type", "application/json")
.body("{\n \"nombre\": \"<string>\",\n \"descripcion\": \"<string>\",\n \"precio\": 123,\n \"precioOriginal\": 123,\n \"stock\": 123,\n \"categoriaId\": 123,\n \"marcaId\": 123,\n \"peso\": 123,\n \"alto\": 123,\n \"ancho\": 123,\n \"profundidad\": 123,\n \"isFeatured\": true\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/products")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n \"nombre\": \"<string>\",\n \"descripcion\": \"<string>\",\n \"precio\": 123,\n \"precioOriginal\": 123,\n \"stock\": 123,\n \"categoriaId\": 123,\n \"marcaId\": 123,\n \"peso\": 123,\n \"alto\": 123,\n \"ancho\": 123,\n \"profundidad\": 123,\n \"isFeatured\": true\n}"
response = http.request(request)
puts response.read_body{
"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 theADMIN role can create products.
Request Headers
Content-Type: multipart/form-data
Authorization: Bearer <access_token>
Request Body
This endpoint acceptsmultipart/form-data to support image upload.
string
required
Product name (minimum 3 characters)
string
required
Product description (minimum 10 characters)
number
required
Product price (must be positive)
number
Original price (for displaying discounts)
number
required
Initial stock quantity (must be non-negative integer)
number
required
Category ID to associate with this product
number
Brand ID to associate with this product
number
default:"0.5"
Product weight in kg
number
default:"10"
Product height in cm
number
default:"10"
Product width in cm
number
default:"10"
Product depth in cm
boolean
default:"false"
Whether this product should be featured
file
Product image file (uploaded as multipart form data)
Response
boolean
Indicates if the product was created successfully
object
The newly created product object
number
Unique product identifier
string
Product name
string
Product description
decimal
Product price
decimal
Original price
number
Stock quantity
string
Uploaded product image URL
boolean
Featured status
decimal
Weight in kg
number
Height in cm
number
Width in cm
number
Depth in cm
number
Category ID
number
Brand ID
datetime
Creation timestamp
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"
}
⌘I