Skip to main content
All order endpoints require authentication. Include a valid authentication token in your request headers.

Create Order

Create a new order. This endpoint validates stock availability, creates the order, reduces product stock, and sends confirmation emails.

Authentication

Required. User must be authenticated via Clerk.

Request Body

orderItems
array
required
Array of items to order
orderItems[].product
object
required
Product object with _id field
orderItems[].name
string
Product name (optional, will use product data if not provided)
orderItems[].price
number
required
Product price at time of order
orderItems[].quantity
number
required
Quantity ordered (minimum 1)
shippingAddress
object
required
Shipping address details
shippingAddress.fullName
string
required
Recipient’s full name
shippingAddress.streetAddress
string
required
Street address
shippingAddress.city
string
required
City
shippingAddress.phoneNumber
string
required
Contact phone number
paymentResult
object
required
Payment result information
paymentResult.id
string
Payment transaction ID
paymentResult.status
string
Payment status (e.g., “succeeded”, “pending”)
totalPrice
number
required
Total order price

Response

message
string
Success message
order
object
The created order object
order._id
string
Order unique identifier
order.user
string
User ID reference
order.clerkId
string
Clerk user ID
order.orderItems
array
Array of ordered items
order.shippingAddress
object
Shipping address details
order.paymentResult
object
Payment result information
order.totalPrice
number
Total order price
order.status
string
Order status: “pending”, “paid”, “in_preparation”, “ready”, “delivered”, “canceled”, “rejected”
order.createdAt
string
ISO 8601 timestamp of order creation

Example Request

curl -X POST https://api.donpalitojr.com/api/orders \
  -H "Authorization: Bearer YOUR_AUTH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "orderItems": [
      {
        "product": {"_id": "65f8a1b2c3d4e5f6g7h8i9j3"},
        "name": "Empanada de Pollo",
        "price": 3500,
        "quantity": 2
      }
    ],
    "shippingAddress": {
      "fullName": "Juan Pérez",
      "streetAddress": "Calle 123 #45-67",
      "city": "Bogotá",
      "phoneNumber": "+57 300 123 4567"
    },
    "paymentResult": {
      "id": "transfer_1234567890",
      "status": "pending"
    },
    "totalPrice": 7000
  }'

Example Response

{
  "message": "Order created successfully",
  "order": {
    "_id": "65f8a1b2c3d4e5f6g7h8i9j0",
    "user": "65f8a1b2c3d4e5f6g7h8i9j1",
    "clerkId": "user_2abc123def456",
    "orderItems": [
      {
        "product": "65f8a1b2c3d4e5f6g7h8i9j3",
        "name": "Empanada de Pollo",
        "price": 3500,
        "quantity": 2
      }
    ],
    "shippingAddress": {
      "fullName": "Juan Pérez",
      "streetAddress": "Calle 123 #45-67",
      "city": "Bogotá",
      "phoneNumber": "+57 300 123 4567"
    },
    "paymentResult": {
      "id": "transfer_1234567890",
      "status": "pending"
    },
    "totalPrice": 7000,
    "status": "pending",
    "createdAt": "2024-03-15T10:30:00.000Z"
  }
}

Error Responses

400 Bad Request
No order items or insufficient stock
{
  "error": "No order items"
}
{
  "error": "Insufficient stock for Empanada de Pollo"
}
404 Not Found
Product not found
{
  "error": "Product Empanada de Pollo not found"
}

Get User Orders

Retrieve all orders for the authenticated user, sorted by most recent first. Includes review status for each order.

Authentication

Required. User must be authenticated via Clerk.

Response

orders
array
Array of order objects
orders[]._id
string
Order unique identifier
orders[].orderItems
array
Array of ordered items with populated product details (name, images, price)
orders[].shippingAddress
object
Shipping address details
orders[].totalPrice
number
Total order price
orders[].status
string
Current order status
orders[].hasReviewed
boolean
Whether the user has reviewed this order
orders[].createdAt
string
ISO 8601 timestamp of order creation
orders[].paidAt
string
ISO 8601 timestamp when order was paid
orders[].deliveredAt
string
ISO 8601 timestamp when order was delivered

Example Request

curl -X GET https://api.donpalitojr.com/api/orders \
  -H "Authorization: Bearer YOUR_AUTH_TOKEN"

Example Response

{
  "orders": [
    {
      "_id": "65f8a1b2c3d4e5f6g7h8i9j0",
      "orderItems": [
        {
          "_id": "65f8a1b2c3d4e5f6g7h8i9j2",
          "product": {
            "_id": "65f8a1b2c3d4e5f6g7h8i9j3",
            "name": "Empanada de Pollo",
            "images": ["https://res.cloudinary.com/xxx/products/empanada1.jpg"],
            "price": 3500
          },
          "name": "Empanada de Pollo",
          "price": 3500,
          "quantity": 2
        }
      ],
      "shippingAddress": {
        "fullName": "Juan Pérez",
        "streetAddress": "Calle 123 #45-67",
        "city": "Bogotá",
        "phoneNumber": "+57 300 123 4567"
      },
      "totalPrice": 7000,
      "status": "delivered",
      "hasReviewed": false,
      "createdAt": "2024-03-15T10:30:00.000Z",
      "paidAt": "2024-03-15T11:00:00.000Z",
      "deliveredAt": "2024-03-16T14:30:00.000Z"
    }
  ]
}

Download Invoice

Download a PDF invoice for a paid or delivered order.

Authentication

Required. User must be authenticated via Clerk and must own the order.

Path Parameters

orderId
string
required
The order ID to download invoice for

Response

Returns a PDF file as application/pdf with filename factura-FV-YYYY-XXXXXXXX.pdf.

Example Request

curl -X GET https://api.donpalitojr.com/api/orders/65f8a1b2c3d4e5f6g7h8i9j0/invoice \
  -H "Authorization: Bearer YOUR_AUTH_TOKEN" \
  --output invoice.pdf

Error Responses

400 Bad Request
Invoice only available for paid or delivered orders
{
  "error": "La factura solo está disponible para pedidos pagados o entregados."
}
403 Forbidden
User is not authorized to access this order
{
  "error": "No autorizado."
}
404 Not Found
Order not found
{
  "error": "Pedido no encontrado."
}

Build docs developers (and LLMs) love