Skip to main content

Update Cart

Update currently authenticated user cart

HTTP Request

PATCH/api/shop/cart

Authorization

Authorization

  • Required: Yes
  • Permission: Authenticated User
  • Authentication: Token-based (Authorization: Token <your_api_key>)

Request Body

FieldTypeRequiredDescription
addressIntegerNoAddress id related to the cart
shipping_methodIntegerNoshipping method id related to the cart
payment_methodIntegerNopayment_method id related to the cart

Example Requests

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())

Response Fields

FieldTypeDescription
idIntegerUnique ID of the product
addressIntegerSelected delivery address ID
shipping_methodIntegerSelected shipping method ID
payment_methodIntegerSelected payment method ID
created_atString (ISO 8601)Timestamp when cart was created
updated_atString (ISO 8601)Timestamp when cart was last updated
countIntegerNumber of unique items in cart
quantityIntegerTotal quantity of all items
is_emptyBooleanWhether the cart is empty
items_subtotalIntegerSubtotal of all items before discounts
items_discountIntegerTotal discount amount on items
subtotalIntegerCart subtotal after item discounts
discountIntegerAdditional cart-level discount
shipping_costIntegerShipping cost of the cart
totalIntegerFinal cart total
itemsArrayArray of cart items (see Cart Item fields)

Cart Item Fields

FieldTypeDescription
idIntegerUnique ID of the cart item
refStringCart Item reference (read-only)
productObjectProduct information with `id`, `name`, `image`
quantityIntegerItem quantity
notesStringCustomer notes for this item
created_atString (ISO 8601)Timestamp when item was added
updated_atString (ISO 8601)Timestamp when item was last updated
unit_priceIntegerPrice per unit (read-only)
unit_discountIntegerDiscount per unit (read-only)
subtotalIntegerItem subtotal before discount (read-only)
discountIntegerTotal item discount (read-only)
totalIntegerFinal item total (read-only)

Product Object Data Structure

FieldTypeDescription
idIntegerUnique id of the product
titleStringProduct title
imageObjectProduct image details

Image Data Structure

FieldTypeDescription
idIntegerUnique ID of the image
typeStringFile type (e.g., image/jpeg)
nameStringOriginal file name
sizeIntegerFile size in bytes
human_readable_sizeStringHuman readable file size (e.g., 2.5 MB)
fStringURL to access the image file
widthIntegerImage width in pixels
heightIntegerImage height in pixels
modeStringColor mode (e.g., RGB, CMYK)
thumbnailsList of thumbnail objectsImgae thumbnails

Thumbnail Data Structure

FieldTypeDescription
idIntegerUnique ID of the thumbnail (unique)
fStringURL to access the thumbnail file
sizeIntegerFile size in bytes (nullable)

Example Response

{
"id": 1,
"address": 1,
"shipping_method": 1,
"payment_method": 1,
"created_at": "2025-11-22T15:26:59.108182Z",
"updated_at": "2025-12-30T12:53:24.505447Z",
"count": 2,
"quantity": 8,
"is_empty": false,
"items_subtotal": 48004000,
"items_discount": 4960400,
"subtotal": 48004000,
"discount": 4960400,
"shipping_cost": 0,
"total": 43043600,
"items": [
{
"id": 3,
"ref": "54",
"product": {
"id": 54,
"title": "درب سمت راست پراید",
"image": null
},
"quantity": 4,
"notes": "Rem itaque perferendis id ipsam accusamus tenetur est sunt. Qui est fuga iste. Eum voluptatem nam consectetur praesentium quaerat aut. Libero ut culpa laudantium eum voluptatem omnis quod. Ratione a aut consequuntur fugit ut.",
"created_at": "2025-12-30T12:33:18.957141Z",
"updated_at": "2025-12-30T12:33:18.957148Z",
"unit_price": 1000,
"unit_discount": 100,
"subtotal": 4000,
"discount": 400,
"total": 3600
},
{
"id": 2,
"ref": "36",
"product": {
"id": 36,
"title": "ماوس لاجیتک MX Vertical",
"image": {
"id": 2,
"type": "image",
"name": "logitech-mx-1",
"size": 4766,
"human_readable_size": "4.65 KB",
"f": "http://127.0.0.1:8000/media/core_media/2025/11/22/logitech-mx-1.jpg",
"width": 225,
"height": 225,
"mode": "RGB",
"thumbnails": [
{
"id": 213,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_64x64.jpg",
"size": 64
},
{
"id": 214,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_128x128.jpg",
"size": 128
},
{
"id": 215,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_512x512.jpg",
"size": 512
},
{
"id": 216,
"f": "http://127.0.0.1:8000/media/core_media/2026/02/02/thumbnails/test2_ecH0zVV_thumbnail_1080x1080.jpg",
"size": 1080
}
]
}
},
"quantity": 4,
"notes": "placeat",
"created_at": "2025-12-30T12:33:03.257543Z",
"updated_at": "2025-12-30T12:33:03.257550Z",
"unit_price": 12000000,
"unit_discount": 1240000,
"subtotal": 48000000,
"discount": 4960000,
"total": 43040000
}
]
}