Cart
Overview
The cart can be used by both anonymous and registered users. A registered user needs a Bearer token, while an anonymous user can use a special basket token, which can be obtained, for example, when receiving the contents of the basket, and then transmitted in the headers.
1. Cart content
Endpoint
GET /api/v1/shop/cart
Request Headers
{
"Authorization": "Bearer token here (OPTIONAL)",
"X-API-Key": "123456789",
"Content-Type": "application/json",
"X-Cart-ID": "guest_763d1369-5bb8-4745-9e4d-4612126bcdb8 (OPTIONAL)"
}
Request Body
{}
Expected Response for unregistered user
{
"message": "Cart retrieved successfully",
"cart_id": "guest_763d1369-5bb8-4745-9e4d-4612126bcdb8",
"data": {
"id": "guest_763d1369-5bb8-4745-9e4d-4612126bcdb8",
"total": 0,
"formatted_total": "0.00",
"items_count": 0,
"items_quantity": 0,
"is_empty": true,
"items": []
},
"is_new_cart": false
}
Expected Response for registered user
{
"message": "Cart retrieved successfully",
"cart_id": "user_32",
"data": {
"id": "user_32",
"total": 82,
"formatted_total": "82.00",
"items_count": 1,
"items_quantity": 2,
"is_empty": false,
"items": [
{
"id": 2,
"sku": "EH-2",
"name": "My second product 2",
"price": 41,
"quantity": 2,
"subtotal": 82,
"options": {
"color": "re3",
"size": "XL3"
},
"stock": 200,
"type": "simple",
"meta": []
}
]
},
"is_new_cart": false
}
2. Add item (product) to cart
Endpoint
POST /api/v1/shop/cart/{productSku}
Request Headers
{
"Authorization": "Bearer token here (OPTIONAL)",
"X-API-Key": "123456789",
"Content-Type": "application/json",
"X-Cart-ID": "guest_763d1369-5bb8-4745-9e4d-4612126bcdb8 (OPTIONAL)"
}
Request Body
{
"quantity": 2,
"options": {
"color": "red",
"size": "XL"
}
}
Expected Response
{
"message": "Product added to cart successfully",
"cart_id": "user_32",
"data": {
"id": "user_32",
"total": 246,
"formatted_total": "246.00",
"items_count": 1,
"items_quantity": 6,
"is_empty": false,
"items": [
{
"id": 2,
"sku": "EH-2",
"name": "My second product 2",
"price": 41,
"quantity": 6,
"subtotal": 246,
"options": {
"color": "red",
"size": "XL"
},
"stock": 200,
"type": "simple",
"meta": []
}
]
},
"added_item": {
"id": 2,
"sku": "EH-2",
"name": "My second product 2",
"price": 41,
"quantity": 6,
"subtotal": 246,
"options": {
"color": "red",
"size": "XL"
},
"stock": 200,
"type": "simple",
"meta": []
}
}
3. Update item (product) to cart
Endpoint
PUT /api/v1/shop/cart/{productSku}
Request Headers
{
"Authorization": "Bearer token here (OPTIONAL)",
"X-API-Key": "123456789",
"Content-Type": "application/json",
"X-Cart-ID": "guest_763d1369-5bb8-4745-9e4d-4612126bcdb8 (OPTIONAL)"
}
Request Body
{
"quantity": 2,
"options": {
"color": "red",
"size": "XL"
}
}
Expected Response
{
"message": "Cart item updated successfully",
"cart_id": "user_32",
"data": {
"id": "user_32",
"total": 41,
"formatted_total": "41.00",
"items_count": 1,
"items_quantity": 1,
"is_empty": false,
"items": [
{
"id": 2,
"sku": "EH-2",
"name": "My second product 2",
"price": 41,
"quantity": 1,
"subtotal": 41,
"options": {
"color": "red",
"size": "XL"
},
"stock": 200,
"type": "simple",
"meta": []
}
]
},
"updated_item": {
"id": 2,
"sku": "EH-2",
"name": "My second product 2",
"price": 41,
"quantity": 1,
"subtotal": 41,
"options": {
"color": "red",
"size": "XL"
},
"stock": 200,
"type": "simple",
"meta": []
}
}
4. Delete item (product) in cart
Endpoint
DELETE /api/v1/shop/cart/{productSku}
Request Headers
{
"Authorization": "Bearer token here (OPTIONAL)",
"X-API-Key": "123456789",
"Content-Type": "application/json",
"X-Cart-ID": "guest_763d1369-5bb8-4745-9e4d-4612126bcdb8 (OPTIONAL)"
}
Request Body
{}
Expected Response
{
"message": "Cart item removed successfully",
"cart_id": "user_32",
"data": {
"id": "user_32",
"total": 0,
"formatted_total": "0.00",
"items_count": 0,
"items_quantity": 0,
"is_empty": true,
"items": []
}
}
5. Delete all items in cart (Clear cart)
Endpoint
DELETE /api/v1/shop/cart
Request Headers
{
"Authorization": "Bearer token here (OPTIONAL)",
"X-API-Key": "123456789",
"Content-Type": "application/json",
"X-Cart-ID": "guest_763d1369-5bb8-4745-9e4d-4612126bcdb8 (OPTIONAL)"
}
Request Body
{}
Expected Response
{
"message": "Cart cleared successfully",
"cart_id": "user_32",
"data": {
"id": "user_32",
"total": 0,
"formatted_total": "0.00",
"items_count": 0,
"items_quantity": 0,
"is_empty": true,
"items": []
}
}
31 March 2025