Skip to main content

Add Item to Cart

Adds a new product to the cart or increases quantity if the product already exists.

HTTP Request

POST/api/shop/cart/items

Authorization

Authorization

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

Request Body

FieldTypeRequiredDescription
productIntegerYesProduct ID to add to cart
quantityIntegerNoQuantity to add (default: 1, minimum: 1)
notesStringNoCustomer notes for this item (max 500 chars)

Example Requests

1import requests
2
3# Add product to cart
4response = requests.post('http://www.example.com/api/shop/cart/items', 
5  json={
6      'product': 123,
7      'quantity': 2,
8      'notes': 'Please pack carefully'
9  },
10  headers={'Authorization': 'Token <your_api_key>'}
11)
12print(response.json())
13
14# Add single item
15response = requests.post('http://www.example.com/api/shop/cart/items', 
16  json={
17      'product': 456
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
totalIntegerFinal cart total
itemsArrayArray of cart items (see Cart Item fields)

Cart Item Fields

FieldTypeDescription
idIntegerUnique ID of the cart item
refStringItem 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)

Example Respones

{
"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": 1,
"quantity": 2,
"is_empty": false,
"items_subtotal": 2000,
"items_discount": 200,
"subtotal": 2000,
"discount": 200,
"shipping_cost": 0,
"total": 1800,
"items": [
{
"id": 4,
"ref": "54",
"product": {
"id": 54,
"title": "درب سمت راست پراید",
"image": null
},
"quantity": 2,
"notes": "Ut facilis aspernatur odit molestiae. Voluptates eveniet nihil sed qui. Soluta ex quo eum. Magni asperiores aliquam et. Vel qui molestiae culpa autem.",
"created_at": "2025-12-30T13:17:46.941326Z",
"updated_at": "2025-12-30T13:17:46.941335Z",
"unit_price": 1000,
"unit_discount": 100,
"subtotal": 2000,
"discount": 200,
"total": 1800
}
]
}