Manage shopping carts, items, discounts, and cart-related operations in the checkout system.
/api/cart
The Cart API provides comprehensive endpoints for managing shopping carts including creation, item management, discount application, and cart merging. Supports both authenticated and guest carts.
Creates a new shopping cart for authenticated or guest user.
{
"customerId": "cust_123",
"currency": "USD",
"cartType": "authenticated"
}
{
"cartId": "cart_789",
"customerId": "cust_123",
"currency": "USD",
"items": [],
"subtotal": 0,
"tax": 0,
"total": 0,
"createdAt": "2026-06-02T10:30:00Z"
}
Gets cart details with all items and totals.
| Parameter | Type |
|---|---|
| cartId | string |
{
"cartId": "cart_789",
"customerId": "cust_123",
"currency": "USD",
"items": [
{
"cartItemId": "item_1",
"offerId": "offer_456",
"quantity": 2,
"price": 99.99,
"amount": 199.98
}
],
"discounts": [
{
"code": "SAVE10",
"type": "percentage",
"value": 10,
"amount": 19.99
}
],
"subtotal": 199.98,
"discount": 19.99,
"tax": 18.00,
"total": 197.99,
"createdAt": "2026-06-02T10:30:00Z"
}
Deletes a shopping cart and all items.
| Parameter | Type |
|---|---|
| cartId | string |
{
"success": true,
"message": "Cart deleted"
}
Gets active cart for a customer.
| Parameter | Type |
|---|---|
| customerId | string |
{
"cartId": "cart_789",
"customerId": "cust_123",
"items": [],
"total": 0,
"createdAt": "2026-06-02T10:30:00Z"
}
Merges guest cart items into authenticated customer cart.
{
"guestCartId": "cart_guest_123",
"customerCartId": "cart_789",
"mergeStrategy": "add"
}
{
"cartId": "cart_789",
"itemsMerged": 3,
"total": 299.97,
"mergedAt": "2026-06-02T10:35:00Z"
}
Adds a product offer to the cart.
{
"offerId": "offer_456",
"quantity": 2,
"price": 99.99
}
{
"cartItemId": "item_1",
"offerId": "offer_456",
"quantity": 2,
"price": 99.99,
"amount": 199.98,
"addedAt": "2026-06-02T10:30:00Z"
}
Updates quantity or price of a cart item.
{
"quantity": 3,
"price": 99.99
}
{
"cartItemId": "item_1",
"offerId": "offer_456",
"quantity": 3,
"amount": 299.97,
"updatedAt": "2026-06-02T10:35:00Z"
}
Removes a specific item from the cart.
{
"success": true,
"message": "Item removed from cart"
}
Applies a discount or promotional code to the cart.
{
"code": "SAVE10",
"type": "percentage"
}
{
"code": "SAVE10",
"type": "percentage",
"value": 10,
"amount": 19.99,
"newTotal": 180.99,
"appliedAt": "2026-06-02T10:40:00Z"
}
Removes a discount code from the cart.
{
"success": true,
"message": "Discount removed",
"newTotal": 199.98
}
| Code | HTTP Status | Description |
|---|---|---|
| CART_NOT_FOUND | 404 | Cart does not exist |
| ITEM_NOT_FOUND | 404 | Cart item does not exist |
| INVALID_DISCOUNT | 400 | Discount code is invalid or expired |
| INSUFFICIENT_INVENTORY | 400 | Not enough stock for requested quantity |