- Explicit Cart Creation: Carts must be created before items can be added.
- Persistent Carts: Carts are tied to the user.
- Item Management: Add, update quantity, or remove products and variants to an existing cart.
- Pricing Calculation: Automatically calculates subtotals, taxes, shipping, and grand totals.
- Discount Application: Apply coupon codes, automatic promotions, loyalty points, and store credit.
- Address Management: Set billing and shipping addresses for checkout calculation.
- Fulfillment Options: Fetch fulfillment options and update fulfillment preferences per shipment.
- User Association: Carts link to anonymous or logged-in users; retrievable via
user_idfor both.
Core Concepts
Cart Lifecycle & Persistence
Cart Lifecycle & Persistence
- Creation: A cart must always be explicitly created using
POST /cartsbefore any items can be added. This endpoint requires at least one item to be included in the request body for successful cart creation. There is no concept of creating an empty cart via the API initially. - Association: Every cart is linked to a user automatically upon creation.
- Retrieval: You can retrieve a specific cart using its
id(GET /carts/{id}) or retrieve the active cart associated with a user (both anonymous and logged-in) via theiruser_id(GET /carts/users/{user_id}). This allows fetching the correct cart even if the client loses thecart_idbut still has the user’s token/ID. - Persistence: Carts persist across sessions as long as the user context (
user_id) remains the same. - Expiration: Carts have an
expires_attimestamp. Inactive carts may be cleaned up after this time. Active interaction typically extends the expiry. - Transition to Order: The final state of the cart (identified by its
id) is used as the basis for creating an order via thePOST /ordersendpoint.
Cart inheritance and merging upon login
Cart inheritance and merging upon login
Cart Structure (Cart Object)
Cart Structure (Cart Object)
-
id: The unique identifier for this cart. -
active: Boolean indicating if the cart is still active. -
cart_items: An array ofCartItemobjects detailing each product/variant in the cart. -
cart_items_count: Total number of unique line items. -
Pricing Summary:
subtotal: Sum of item selling prices (before tax and discounts).items_tax_amount: Total tax calculated on items.subtotal_including_tax: Subtotal + Item Tax.shipping_amount: Calculated shipping cost (before tax).shipping_tax_amount: Tax on shipping.shipping_amount_including_tax: Shipping + Shipping Tax.total_tax:items_tax_amount+shipping_tax_amount+handling_charge_tax_amount.grand_total: The final amount after all deductions, including taxes but before loyalty points are redeemed.
-
Discounts & Redemptions:
is_promotion_applied,promotion_discount_amount: For automatic promotions.is_coupon_applied,coupon_code,coupon_discount_amount: For user-applied coupons.loyalty_points_redeemed: Points applied as discount.loyalty_points_earned: Points the user will earn if this cart becomes an order.credit_balance_used: Store credit/wallet balance applied.to_be_paid: The amount to display at checkout. This is what the customer actually pays (grand_total-loyalty_points_redeemed_value-credit_balance_used). Always displayto_be_paidrather thangrand_totalas the final price — it accounts for loyalty points and credit balance deductions.
-
Addresses:
billing_address:CustomerAddressobject.shipping_address:CustomerAddressobject.customer_email,customer_phone,customer_note: User details associated with the cart.currency: Currency details (code,symbol,name).metadata: Custom key-value pairs.expires_at: Timestamp when the cart might expire if inactive.
Cart Items (CartItem Object)
Cart Items (CartItem Object)
product_id,variant_id,sku: Identifiers for the item.product_name,variant_name,product_image_url: Display details.quantity: The number of this item in the cart.stock_available,on_offer,on_promotion,on_subscription: Status flags.listing_price,selling_price: Per-unit prices.promotion_discount_amount,coupon_discount_amount: Discounts applied to this line item.tax_type,tax_rate,tax_amount: Tax details for this line item.shipping_additional_cost: Any per-item shipping surcharge.associated_options: Details of selected variant options (e.g., Color: Red, Size: Large).subscriptions: Details if this item is being added as part of a subscription plan.is_free_item,free_quantity: Indicates if quantity is part of a “free goods” promotion.
Cart API Endpoints
POST /carts
POST /carts
items array to successfully create the cart. It cannot be used to create an empty cart. This is typically the first cart-related call when a user adds their initial item.- Authentication: Bearer Token (Anonymous or Logged-in)
-
Request Body (Required): (See
UpdateCartItemschema)Create Cart Request Body -
Response:
200 OKwith the newly createdCartobject, including its uniqueid. Store thisidfor subsequent cart operations.
GET /carts/{id}
GET /carts/{id}
- Authentication: Bearer Token (Must match the user associated with the cart ID)
- Path Parameter:
id(Cart ID obtained fromPOST /cartsor a previous cart state) - Response:
200 OKwith theCartobject, or404 Not Found.
DELETE /carts/{id}
DELETE /carts/{id}
- Authentication: Bearer Token (Must match the user associated with the cart ID)
- Path Parameter:
id(Cart ID) - Response:
200 OKwith success message, or404 Not Found.
GET /carts/users/{user_id}
GET /carts/users/{user_id}
user_id from the user object obtained via /auth/anonymous or login flows.- Authentication: Bearer Token (Token must correspond to the user session associated with
{user_id}) - Path Parameter:
user_id - Response:
200 OKwith theCartobject, or404 Not Foundif no active cart exists for the user.
DELETE /carts/users/{user_id}
DELETE /carts/users/{user_id}
- Authentication: Bearer Token (Token must correspond to the user session associated with
{user_id}) - Path Parameter:
user_id - Response:
200 OKwith success message, or404 Not Found.
POST /carts/{id}/items
POST /carts/{id}/items
POST /carts for initial creation.- Authentication: Bearer Token (Must match the user associated with the cart ID)
-
Path Parameter:
id(Required Cart ID obtained fromPOST /cartsorGETrequests) -
Request Body:
UpdateCartItemschema:product_id: Required ID of the product.variant_id: Required ID of the variant (usenullif the product has no variants).quantity: The desired total quantity for this item in the cart.quantity > 0: Adds or updates the item to this quantity.quantity = 0: Removes the item from the cart.
-
Response:
200 OKwith the updatedCartobject reflecting the changes and recalculated totals. Returns400 Bad Requestif quantity exceeds stock or validation fails, or404 Not Foundif the Cart ID is invalid.Add/Update/Remove Item Request Body
POST /carts/{id}/address
POST /carts/{id}/address
- Authentication: Bearer Token
- Path Parameter:
id(Cart ID) - Request Body:
oneOfsaved address IDs (logged-in users) or fullCustomerAddressobjects (guests or new address). (Schema details unchanged) - Response:
200 OKwith the updatedCartobject.
POST /carts/{id}/coupon
POST /carts/{id}/coupon
- Authentication: Bearer Token
- Path Parameter:
id(Cart ID) - Request Body:
Apply Coupon Request Body
- Response:
200 OKwith the updatedCartobject, or400 Bad Request.
400 Bad Request error, potentially with a message indicating login is required. Consider prompting users to log in before applying coupons with such restrictions.DELETE /carts/{id}/coupon
DELETE /carts/{id}/coupon
- Authentication: Bearer Token
- Path Parameter:
id(Cart ID) - Response:
200 OKwith the updatedCartobject.
Redeem/Remove Loyalty Points & Credit Balance
Redeem/Remove Loyalty Points & Credit Balance
POST /carts/{id}/loyalty-points, DELETE /carts/{id}/loyalty-points, POST /carts/{id}/credit-balance, DELETE /carts/{id}/credit-balance remain functionally the same, requiring a logged-in user’s token.)Wishlist Endpoints
Wishlist Endpoints
GET /wishlist/{user_id}, POST /wishlist/{user_id}, DELETE /wishlist/{user_id} remain functionally the same, requiring a logged-in user’s token.)Common Use Cases & Flows
Adding the First Item to the Cart
Adding the First Item to the Cart
Adding Subsequent Items / Updating Quantity / Removing
Adding Subsequent Items / Updating Quantity / Removing
Retrieving Cart on Page Load / After Login
Retrieving Cart on Page Load / After Login