Skip to main content
POST
/
orders
Create Order
curl --request POST \
  --url https://api.example.com/orders
{
  "id": 42,
  "userId": 5,
  "total": "149.97",
  "status": "pending",
  "createdAt": "2026-03-06T10:30:00.000Z",
  "updatedAt": "2026-03-06T10:30:00.000Z"
}
Creates a new order by converting all items in the authenticated user’s cart into an order. This endpoint:
  • Validates that the cart is not empty
  • Calculates the total price based on current product prices
  • Creates order items with the price at time of purchase
  • Reduces product stock atomically
  • Clears the cart after successful order creation

Authentication

This endpoint requires authentication. Include a valid JWT token in the Authorization header.
Authorization: Bearer <your-token>

Request

No request body is required. The order is created from the user’s current cart contents.

Response

id
number
required
Unique identifier for the order
userId
number
required
ID of the user who placed the order
total
string
required
Total amount for the order (decimal as string)
status
string
required
Current status of the order. Defaults to pending.Possible values:
  • pending - Order has been created but not yet processed
  • shipped - Order has been shipped
  • delivered - Order has been delivered
  • cancelled - Order has been cancelled
createdAt
string
required
ISO 8601 timestamp when the order was created
updatedAt
string
required
ISO 8601 timestamp when the order was last updated
{
  "id": 42,
  "userId": 5,
  "total": "149.97",
  "status": "pending",
  "createdAt": "2026-03-06T10:30:00.000Z",
  "updatedAt": "2026-03-06T10:30:00.000Z"
}

Error Responses

400 Bad Request

Returned when:
  • The cart is empty
  • Insufficient stock for one or more products
{
  "error": "El carrito está vacío"
}
{
  "error": "Stock insuficiente para el producto \"Wireless Headphones\""
}

401 Unauthorized

Returned when the authentication token is missing or invalid.
{
  "error": "Usuario no autenticado"
}

Build docs developers (and LLMs) love