All cart endpoints require authentication. Include a valid authentication token in your request headers.
Get Cart
Retrieve the current user’s shopping cart. Creates an empty cart if one doesn’t exist.
Authentication
Required. User must be authenticated via Clerk.
Response
Array of cart items with populated product details
Full product object with name, price, images, etc.
Quantity of this product in cart (minimum 1)
Example Request
curl -X GET https://api.donpalitojr.com/api/cart \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
Example Response
{
"cart": {
"_id": "65f8a1b2c3d4e5f6g7h8i9j0",
"user": "65f8a1b2c3d4e5f6g7h8i9j1",
"clerkId": "user_2abc123def456",
"items": [
{
"_id": "65f8a1b2c3d4e5f6g7h8i9j2",
"product": {
"_id": "65f8a1b2c3d4e5f6g7h8i9j3",
"name": "Empanada de Pollo",
"price": 3500,
"images": ["https://res.cloudinary.com/xxx/products/empanada1.jpg"],
"stock": 50
},
"quantity": 2
}
],
"createdAt": "2024-03-15T10:30:00.000Z",
"updatedAt": "2024-03-15T10:30:00.000Z"
}
}
Add Item to Cart
Add a product to the cart or increment quantity if already present.
Authentication
Required. User must be authenticated via Clerk.
Request Body
The product ID to add to cart
Quantity to add (defaults to 1)
Response
Returns the updated cart with populated product details.
Updated cart object with items array
Example Request
curl -X POST https://api.donpalitojr.com/api/cart \
-H "Authorization: Bearer YOUR_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"productId": "65f8a1b2c3d4e5f6g7h8i9j3",
"quantity": 2
}'
Example Response
{
"cart": {
"_id": "65f8a1b2c3d4e5f6g7h8i9j0",
"items": [
{
"product": {
"_id": "65f8a1b2c3d4e5f6g7h8i9j3",
"name": "Empanada de Pollo",
"price": 3500
},
"quantity": 2
}
]
}
}
Error Responses
Insufficient stock available
{
"error": "Insufficient stock"
}
{
"error": "Product not found"
}
Update Cart Item Quantity
Update the quantity of a specific product in the cart.
Authentication
Required. User must be authenticated via Clerk.
Path Parameters
Request Body
New quantity (must be at least 1)
Response
Returns the updated cart with populated product details.
Example Request
curl -X PUT https://api.donpalitojr.com/api/cart/65f8a1b2c3d4e5f6g7h8i9j3 \
-H "Authorization: Bearer YOUR_AUTH_TOKEN" \
-H "Content-Type: application/json" \
-d '{"quantity": 3}'
Error Responses
Quantity must be at least 1 or insufficient stock
{
"error": "Quantity must be at least 1"
}
{
"error": "Item not found in cart"
}
Remove Item from Cart
Remove a specific product from the cart.
Authentication
Required. User must be authenticated via Clerk.
Path Parameters
The product ID to remove from cart
Response
Returns the updated cart without the removed item.
Example Request
curl -X DELETE https://api.donpalitojr.com/api/cart/65f8a1b2c3d4e5f6g7h8i9j3 \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
Example Response
{
"cart": {
"_id": "65f8a1b2c3d4e5f6g7h8i9j0",
"items": []
}
}
Clear Cart
Remove all items from the cart.
Authentication
Required. User must be authenticated via Clerk.
Response
Returns the cart with an empty items array.
Example Request
curl -X DELETE https://api.donpalitojr.com/api/cart \
-H "Authorization: Bearer YOUR_AUTH_TOKEN"
Example Response
{
"cart": {
"_id": "65f8a1b2c3d4e5f6g7h8i9j0",
"items": []
}
}