Skip to main content

Update Cart Items

UpdateCartItems Mutation

This mutation updates the quantity of an existing simple item in the customer cart, or removes it entirely when the quantity is set to 0. It uses the updateSimpleItem cart action.

Use Cases​

  • Quantity changes: Let customers increase or decrease item quantities from the landing page mini-cart.
  • Remove from cart: Allow removing a line item by setting its quantity to 0.
  • Inline cart editing: Keep customers on the landing page while they refine their cart.

Headers​

Use the same sessionid header as in the other cart SampleAPIs:

{
"sessionid": "Session_3f6a0f1d-9c4a-4f3e-8f4b-1a2b3c4d5e6f"
}

Input Parameters​

  • $storeId: ID! – The store where the cart lives.
  • $item: SimpleItemInput!
    • variantId: ID! – The variant in the cart you want to modify.
    • quantity: Int! – New quantity:
      • > 0 → update the quantity.
      • 0 → remove the item from the cart.

Note: SimpleItemInput also allows itemId, but for this SampleAPI you can rely on variantId + quantity to update/remove.

Behavior​

  • If the variant is already in the cart:
    • Calling UpdateCartItems with quantity > 0 adjusts the quantity.
    • Calling UpdateCartItems with quantity = 0 removes that line item.
  • If the variant is not in the cart, behavior depends on backend rules (typically you should add via AddToCart first).

Response Structure​

Returns an updated Cart object:

  • id, sessionId, status, cartStep – Cart metadata.
  • items – Updated list of items (for simple items):
    • id
    • quantity
    • price / totalPrice (Money)
    • variant (basic product info)
  • receipt – Updated monetary breakdown:
    • subtotal, discount, shipping, tax, automaticDiscount, total.

Example Variables​

Update quantity to 2:

{
"storeId": "Store_cm84j35iy02m001i89iiu2cts",
"item": {
"variantId": "ProductVariant_cmi3ooen020wf01yh5n7ef0ht",
"quantity": 2
}
}

Remove the item completely (set quantity to 0):

{
"storeId": "Store_cm84j35iy02m001i89iiu2cts",
"item": {
"variantId": "ProductVariant_cmi3ooen020wf01yh5n7ef0ht",
"quantity": 0
}
}

Implementation Notes​

  • Use UpdateCartItems from your landing page mini-cart UI to handle both quantity changes and remove actions.
  • Always send the same sessionid header value you used for AddToCart / ReplaceCartItems so all operations target the same cart.
  • After calling this mutation, you can refresh the cart summary via GetCart or rely on the returned cart payload.

GraphQL Endpoint​

https://graphql.wuilt.com

Operation: UpdateCartItems​

Try It Out​

Query​

mutation UpdateCartItems($storeId: ID!, $item: SimpleItemInput!) {
customerActions(storeId: $storeId) {
cart {
updateSimpleItem(item: $item) {
id
sessionId
status
cartStep
items {
... on CartSimpleItem {
id
quantity
price {
amount
currencyCode
}
totalPrice {
amount
currencyCode
}
product {
id
title
shortDescription
descriptionHtml
handle
images {
id
src
altText
width
height
}
}
variant {
id
sku
price {
amount
currencyCode
}
compareAtPrice {
amount
currencyCode
}
image {
id
src
altText
width
height
}
}
}
}
receipt {
subtotal {
amount
currencyCode
}
discount {
amount
currencyCode
}
shipping {
amount
currencyCode
}
tax {
amount
currencyCode
}
automaticDiscount {
amount
currencyCode
}
total {
amount
currencyCode
}
}
}
}
}
}

Query Variables

1
2
3
4
5
6
7

Note: Make sure to change the storeId with your store ID. For guidance on how to get your store ID, reference the Store ID guide.

Authentication​

To use this query, you will need an API key. Click the "API Key" button in the navigation bar to enter your credentials.