Skip to content

Add to Cart

Add a product to the shopping cart with specified quantity and attributes.

Endpoint

POST /api/shop/cart/items

Request Headers

HeaderRequiredDescription
Content-TypeYesapplication/json
X-STOREFRONT-KEYYesYour storefront API key

Request Body

json
{
  "productId": 1,
  "quantity": 2,
  "attributes": {
    "color": "Black",
    "size": "Large"
  }
}
FieldTypeRequiredDescription
productIdintegerYesProduct ID to add
quantityintegerYesQuantity (minimum 1)
attributesobjectNoProduct attributes (color, size, etc.)

Response Fields (201 Created)

FieldTypeDescription
idintegerCart item ID
productIdintegerProduct ID
productNamestringProduct name
quantityintegerQuantity added
pricedecimalUnit price
subtotaldecimalLine item total
attributesobjectSelected attributes

Response Metadata

FieldTypeDescription
messagestringSuccess message
cartTotaldecimalUpdated cart total

Behavior

  • If product already in cart, quantity is increased
  • Stock validation performed
  • Price calculated at time of addition
  • Attributes are validated for configurable products

Use Cases

  • Add product to cart from product page
  • Update quantity by adding more
  • Support cart on product detail pages
  • Build "Quick Add" functionality

Released under the MIT License.