Skip to main content

Add a product to cart

Add an item to a cart and get the updated totals.

Mutation

mutation AddToCart($cartId: String!, $productId: Int!, $quantity: Int!) {
cartAddItem(
id: $cartId
input: { productId: $productId, quantity: $quantity }
) {
items {
itemId
productId
quantity
price
priceNet
totalPrice
totalPriceNet
}
total {
totalGross
totalNet
}
}
}

Variables

{
"cartId": "018dcc9a-f965-7434-8fad-369aa9a8c276",
"productId": 67890,
"quantity": 2
}

Response

{
"data": {
"cartAddItem": {
"items": [
{
"itemId": "a1b2c3",
"productId": 67890,
"quantity": 2,
"price": 15.00,
"priceNet": 18.15,
"totalPrice": 30.00,
"totalPriceNet": 36.30
}
],
"total": {
"totalGross": 30.00,
"totalNet": 36.30
}
}
}
}

How it works

cartAddItem adds the product or increases its quantity if it already exists in the cart. The response returns all cart items with updated totals, so you can refresh the UI in one round trip. Note the price field naming: price and totalPrice are gross (excluding tax), while priceNet and totalPriceNet are net (including tax) — the opposite of what you might expect. Products may have a minimumQuantity or purchaseUnit constraint; the API rejects quantities that violate these.

See also