Cart Item API
This API allows users to manage cart items, including deleting items and updating their quantities in the cart.
Endpoints Overview
| Method | Endpoint | Description |
|---|---|---|
| DELETE | /api/v1/cart/items/<str:item_id>/ |
Remove an item from the cart. |
| PATCH | /api/v1/cart/items/<str:item_id>/ |
Update the quantity of an item in the cart. |
Cart Item API
1. Remove Cart Item
Endpoint
- URL:
/api/v1/cart/items/<str:item_id>/ - Method:
DELETE - Permission Required:
IsAuthenticated
Description
Removes an item from the cart. Only the authenticated user can delete items from their own cart.
Path Parameters
item_id(Required): The ID of the cart item to be deleted.
Example Request
This is the endpoint
DELETE /api/v1/cart/item/123/
Success
{
"message": "Cart item removed successfully"
}
{
"error": "Cart item not found"
}
2. Update Cart Item Quantity
Endpoint
- URL:
/api/v1/cart/items/<int:item_id>/ - Method:
PATCH - Permission Required:
IsAuthenticated
Description
Updates the quantity of a specific cart item. If the new quantity is zero or negative, the item will be removed from the cart.
Path Parameters
item_id(Required): The ID of the cart item to update.
Request Body
quantity(Required): The new quantity for the cart item.
Example Request
This is the endpoint
PATCH /api/v1/cart/items/123/
Request Body
This is the request body
{
"quantity": 5
}
Success
{
"message": "Cart item updated successfully",
"data": {
"id": 123,
"product": "Sample Product",
"quantity": 5,
"variant": {
"id": 12,
"name": "Variant Name",
"stock_quantity": 20
}
}
}
{
"error": "Cart item not found"
}
Error (400 Bad Request)
{
"error": "Only 10 items available in stock"
}