Overview
The Orders API allows you to create, retrieve, update, and delete customer orders. Each order contains customer information, order details, and a collection of order line items (Detalles).
Authentication
All order endpoints require authentication. Include the JWT token in the Authorization header:
Authorization: Bearer {token}
Entity Structure
The Pedido (Order) entity has the following structure:
public class Pedido
{
public int idPedido { get; set; }
public DateTime fecha { get; set; } = DateTime.Now;
public decimal total { get; set; }
public string metodoPago { get; set; } // "tarjeta" o "efectivo"
public int idUsuario { get; set; }
public virtual Usuario Usuario { get; set; }
public virtual ICollection<Detalle> detalles { get; set; }
}
Order Details (Detalles)
Each order contains a collection of line items:
public class Detalle
{
public int idDetalle { get; set; }
public int cantidad { get; set; }
public decimal precioUnitario { get; set; }
public int idProducto { get; set; }
public virtual Producto producto { get; set; }
}
GET /api/Pedidos
Retrieve all orders in the system.
Response Fields
Order creation date and time
Total order amount (calculated from line items)
Payment method: “tarjeta” (card) or “efectivo” (cash)
Customer user ID who placed the order
Customer information including name, email, and address
Array of order line items (products, quantities, prices)
Example Response
[
{
"idPedido": 1,
"fecha": "2026-03-01T10:30:00",
"total": 125.50,
"metodoPago": "tarjeta",
"idUsuario": 5,
"Usuario": {
"idUsuario": 5,
"nombre": "María",
"apellido": "García",
"email": "[email protected]",
"direccion": "Calle Principal 123"
},
"detalles": [
{
"idDetalle": 1,
"cantidad": 2,
"precioUnitario": 45.99,
"idProducto": 1,
"producto": {
"idProducto": 1,
"nombre": "Alimento para Perros Premium"
}
},
{
"idDetalle": 2,
"cantidad": 1,
"precioUnitario": 33.52,
"idProducto": 8,
"producto": {
"idProducto": 8,
"nombre": "Cama para Mascotas"
}
}
]
}
]
Code Example
curl -X GET https://api.huellitas.com/api/Pedidos \
-H "Authorization: Bearer {your_token_here}"
Source: Huellitas.API/Controllers/PedidosController.cs:22
GET /api/Pedidos/
Retrieve a specific order by ID.
Path Parameters
The unique order identifier
Success Response (200 OK)
Returns a single order object with the same structure as shown above.
Error Response (404 Not Found)
Code Example
curl -X GET https://api.huellitas.com/api/Pedidos/1 \
-H "Authorization: Bearer {your_token_here}"
Source: Huellitas.API/Controllers/PedidosController.cs:28
POST /api/Pedidos
Create a new order.
Request Body
Order date (defaults to current date/time if not provided)
Total order amount (decimal with 2 precision)
Payment method: “tarjeta” or “efectivo” (max 50 characters)
Customer user ID (must be a valid existing user)
Array of order line itemsUnit price at the time of order
Request Example
{
"fecha": "2026-03-04T14:30:00",
"total": 91.98,
"metodoPago": "tarjeta",
"idUsuario": 5,
"detalles": [
{
"cantidad": 2,
"precioUnitario": 45.99,
"idProducto": 1
}
]
}
Success Response (201 Created)
Returns the created order object with the assigned idPedido and a Location header pointing to the new resource.
Error Response (400 Bad Request)
"Error message describing what went wrong"
Code Example
curl -X POST https://api.huellitas.com/api/Pedidos \
-H "Authorization: Bearer {your_token_here}" \
-H "Content-Type: application/json" \
-d '{
"total": 91.98,
"metodoPago": "tarjeta",
"idUsuario": 5,
"detalles": [
{
"cantidad": 2,
"precioUnitario": 45.99,
"idProducto": 1
}
]
}'
const nuevoPedido = {
total: 91.98,
metodoPago: "tarjeta",
idUsuario: 5,
detalles: [
{
cantidad: 2,
precioUnitario: 45.99,
idProducto: 1
}
]
};
const response = await fetch('https://api.huellitas.com/api/Pedidos', {
method: 'POST',
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json'
},
body: JSON.stringify(nuevoPedido)
});
if (response.status === 201) {
const pedido = await response.json();
console.log('Pedido creado con ID:', pedido.idPedido);
}
Source: Huellitas.API/Controllers/PedidosController.cs:36
PUT /api/Pedidos/
Update an existing order.
Path Parameters
The unique order identifier to update
Request Body
Provide the complete order object with updated values. The structure is the same as the POST request.
Success Response (204 No Content)
Returns no content. The 204 status code indicates the update was successful.
Error Response (400 Bad Request)
"Error message describing what went wrong"
Code Example
curl -X PUT https://api.huellitas.com/api/Pedidos/1 \
-H "Authorization: Bearer {your_token_here}" \
-H "Content-Type: application/json" \
-d '{
"idPedido": 1,
"fecha": "2026-03-01T10:30:00",
"total": 150.00,
"metodoPago": "efectivo",
"idUsuario": 5,
"detalles": [...]
}'
Source: Huellitas.API/Controllers/PedidosController.cs:51
DELETE /api/Pedidos/
Delete an order from the system.
Path Parameters
The unique order identifier to delete
Success Response (200 OK)
"Pedido eliminado correctamente."
Error Response (404 Not Found)
"No se pudo eliminar: El pedido no existe."
Code Example
curl -X DELETE https://api.huellitas.com/api/Pedidos/1 \
-H "Authorization: Bearer {your_token_here}"
Source: Huellitas.API/Controllers/PedidosController.cs:65
Important Notes
- Deleting an order will also delete all associated order details (Detalles) due to cascade delete
- Ensure stock levels are adjusted appropriately when orders are created or deleted
- The total should match the sum of (cantidad × precioUnitario) for all line items
Best Practices
- Calculate Total: Always calculate the order total on the server side to prevent manipulation
- Stock Validation: Verify product availability before creating orders
- Price Consistency: Store the unit price in
Detalle to maintain historical accuracy
- Order Status: Consider adding an order status field for order lifecycle management
- Soft Delete: Consider soft-delete for orders to maintain historical data
- Usuario (
Huellitas.Core/Entities/Usuario.cs): Customer who placed the order
- Producto (
Huellitas.Core/Entities/Producto.cs): Products included in order details
- Detalle (
Huellitas.Core/Entities/Detalle.cs): Individual line items in the order