Skip to main content
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

cart
object
required
The user’s cart object
cart._id
string
Cart identifier
cart.user
string
User ID reference
cart.clerkId
string
Clerk user ID
cart.items
array
Array of cart items with populated product details
cart.items[].product
object
Full product object with name, price, images, etc.
cart.items[].quantity
number
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

productId
string
required
The product ID to add to cart
quantity
number
default:"1"
Quantity to add (defaults to 1)

Response

Returns the updated cart with populated product details.
cart
object
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

400 Bad Request
Insufficient stock available
{
  "error": "Insufficient stock"
}
404 Not Found
Product does not exist
{
  "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

productId
string
required
The product ID to update

Request Body

quantity
number
required
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

400 Bad Request
Quantity must be at least 1 or insufficient stock
{
  "error": "Quantity must be at least 1"
}
404 Not Found
Cart or item not found
{
  "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

productId
string
required
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": []
  }
}

Build docs developers (and LLMs) love