Update Cart
Retrieves the current user's shopping cart with all items and calculated totals.
HTTP Request
PATCH/api/shop/cart
Authorization
Authorization
- Required: Yes
- Permission: Authenticated User
- Authentication: Token-based (Authorization: Token <your_api_key>)
Example Requests
- 🐍 Python
- 🌐 Curl
1import requests
2
3# Update cart settings
4response = requests.patch('http://www.example.com/api/shop/cart/',
5 json={
6 'address': 123,
7 'shipping_method': 2,
8 'payment_method': 1
9 },
10 headers={'Authorization': 'Token <your_api_key>'}
11)
12print(response.json())
13
14# Update only shipping method
15response = requests.patch('http://www.example.com/api/shop/cart/',
16 json={
17 'shipping_method': 3
18 },
19 headers={'Authorization': 'Token <your_api_key>'}
20)
21print(response.json())1# Update cart settings
2curl -X PATCH "http://www.example.com/api/shop/cart/" -H "Authorization: Token <your_api_key>" -H "Content-Type: application/json" -d '{
3 "address": 123,
4 "shipping_method": 2,
5 "payment_method": 1
6}'
7
8# Update only shipping method
9curl -X PATCH "http://www.example.com/api/shop/cart/" -H "Authorization: Token <your_api_key>" -H "Content-Type: application/json" -d '{
10 "shipping_method": 3
11}'Status Codes
| Code | Description |
|---|---|
| 200 | Cart updated successfully |
| 400 | Bad Request — invalid input. Check your request data. |
| 401 | Unauthorized — authentication required |
| 500 | Internal server error |
Response Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the product |
| address | Integer | Selected delivery address ID |
| shipping_method | Integer | Selected shipping method ID |
| payment_method | Integer | Selected payment method ID |
| created_at | String (ISO 8601) | Timestamp when cart was created |
| updated_at | String (ISO 8601) | Timestamp when cart was last updated |
| count | Integer | Number of unique items in cart |
| quantity | Integer | Total quantity of all items |
| is_empty | Boolean | Whether the cart is empty |
| items_subtotal | Integer | Subtotal of all items before discounts |
| items_discount | Integer | Total discount amount on items |
| subtotal | Integer | Cart subtotal after item discounts |
| discount | Integer | Additional cart-level discount |
| total | Integer | Final cart total |
| items | Array | Array of cart items (see Cart Item fields) |
Cart Item Fields
| Field | Type | Description |
|---|---|---|
| id | Integer | Unique ID of the cart item |
| ref | String | Item reference (read-only) |
| product | Object | Product information with `id`, `name`, `image` |
| quantity | Integer | Item quantity |
| notes | String | Customer notes for this item |
| created_at | String (ISO 8601) | Timestamp when item was added |
| updated_at | String (ISO 8601) | Timestamp when item was last updated |
| unit_price | Integer | Price per unit (read-only) |
| unit_discount | Integer | Discount per unit (read-only) |
| subtotal | Integer | Item subtotal before discount (read-only) |
| discount | Integer | Total item discount (read-only) |
| total | Integer | Final item total (read-only) |