Skip to main content
POST
/
api
/
Productos
Create Product
curl --request POST \
  --url https://api.example.com/api/Productos \
  --header 'Content-Type: application/json' \
  --data '
{
  "nombre": "<string>",
  "precio": 123,
  "img": "<string>",
  "stockActual": 123,
  "stockMinimo": 123,
  "idCategoria": 123,
  "descripcion": "<string>"
}
'
{
  "idProducto": 123,
  "nombre": "<string>",
  "precio": 123,
  "img": "<string>",
  "stockActual": 123,
  "stockMinimo": 123,
  "idCategoria": 123,
  "descripcion": "<string>",
  "Categoria": {}
}

Authentication

This endpoint requires authentication. Include the JWT token in the Authorization header.
Authorization: Bearer {token}
This endpoint typically requires admin or manager role permissions.

Request Body

nombre
string
required
Product name (max 100 characters)
precio
decimal
required
Product price (decimal with 2 precision points)
img
string
URL or path to the product image
stockActual
integer
required
Initial stock quantity
stockMinimo
integer
required
Minimum stock threshold before reorder alert
idCategoria
integer
required
Foreign key reference to the product category (must exist)
descripcion
string
Product description

Request Example

{
  "nombre": "Juguete Pelota con Sonido",
  "precio": 8.99,
  "img": "/images/productos/pelota-sonido.jpg",
  "stockActual": 200,
  "stockMinimo": 30,
  "idCategoria": 3,
  "descripcion": "Pelota interactiva con sonido para perros"
}

Response

idProducto
integer
Unique identifier for the newly created product
nombre
string
Product name
precio
decimal
Product price
img
string
Product image URL/path
stockActual
integer
Current stock quantity
stockMinimo
integer
Minimum stock threshold
idCategoria
integer
Category ID
descripcion
string
Product description
Categoria
object
Related category information

Success Response (201 Created)

{
  "idProducto": 15,
  "nombre": "Juguete Pelota con Sonido",
  "precio": 8.99,
  "img": "/images/productos/pelota-sonido.jpg",
  "stockActual": 200,
  "stockMinimo": 30,
  "idCategoria": 3,
  "descripcion": "Pelota interactiva con sonido para perros",
  "Categoria": {
    "idCategoria": 3,
    "nombre": "Juguetes",
    "descripcion": "Juguetes y entretenimiento"
  }
}
The response includes a Location header with the URI of the created resource:
Location: /api/Productos/15

Error Response (400 Bad Request)

"Error message describing what went wrong"
Common errors:
  • Missing required fields
  • Invalid category ID
  • Duplicate product name
  • Invalid data types

Code Example

curl -X POST https://api.huellitas.com/api/Productos \
  -H "Authorization: Bearer {your_token_here}" \
  -H "Content-Type: application/json" \
  -d '{
    "nombre": "Juguete Pelota con Sonido",
    "precio": 8.99,
    "img": "/images/productos/pelota-sonido.jpg",
    "stockActual": 200,
    "stockMinimo": 30,
    "idCategoria": 3,
    "descripcion": "Pelota interactiva con sonido para perros"
  }'
const nuevoProducto = {
  nombre: "Juguete Pelota con Sonido",
  precio: 8.99,
  img: "/images/productos/pelota-sonido.jpg",
  stockActual: 200,
  stockMinimo: 30,
  idCategoria: 3,
  descripcion: "Pelota interactiva con sonido para perros"
};

const response = await fetch('https://api.huellitas.com/api/Productos', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer ' + token,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(nuevoProducto)
});

if (response.status === 201) {
  const producto = await response.json();
  console.log('Producto creado con ID:', producto.idProducto);
}
import requests

nuevo_producto = {
    "nombre": "Juguete Pelota con Sonido",
    "precio": 8.99,
    "img": "/images/productos/pelota-sonido.jpg",
    "stockActual": 200,
    "stockMinimo": 30,
    "idCategoria": 3,
    "descripcion": "Pelota interactiva con sonido para perros"
}

headers = {
    'Authorization': f'Bearer {token}',
    'Content-Type': 'application/json'
}

response = requests.post('https://api.huellitas.com/api/Productos', 
                        json=nuevo_producto, 
                        headers=headers)

if response.status_code == 201:
    producto = response.json()
    print(f"Producto creado con ID: {producto['idProducto']}")

Source Reference

Controller: Huellitas.API/Controllers/ProductosController.cs:50 Entity: Huellitas.Core/Entities/Producto.cs

Build docs developers (and LLMs) love