updateCartItems mutation

The updateCartItems mutation allows you to replace the current quantity of one or more cart items with the specified quantities. It does not perform calculations to determine the quantity of cart items.

Setting the quantity to 0 removes an item from the cart.

Syntax

mutation: {updateCartItems(input: UpdateCartItemsInput): {UpdateCartItemsOutput}}

Example usage

The following example changes the quantity of cart item 13. The new quantity is 3.

Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
mutation {
  updateCartItems(
    input: {
      cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG",
      cart_items: [
        {
          cart_item_id: 13
          quantity: 3
        }
      ]
    }
  ){
    cart {
      items {
        id
        product {
          name
        }
        quantity
      }
      prices {
        grand_total{
          value
          currency
        }
      }
    }
}

Response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{
  "data": {
    "updateCartItems": {
      "cart": {
        "items": [
          {
            "id": "13",
            "product": {
              "name": "Strive Shoulder Pack"
            },
            "quantity": 3
          },
          {
            "id": "14",
            "product": {
              "name": "Affirm Water Bottle "
            },
            "quantity": 1
          }
        ],
        "prices": {
          "grand_total": {
            "value": 103,
            "currency": "USD"
          }
        }
      }
    }
  }
}

Input attributes

The UpdateCartItemsInput object is listed first. All child objects are listed in alphabetical order.

UpdateCartItemsInput object

The UpdateCartItemsInput object must contain the following attributes:

Attribute Data Type Description
cart_id String! The unique ID that identifies the customer’s cart
cart_items CartItemUpdateInput! Contains the cart item IDs and quantity of each item

CartItemUpdateInput object

The CartItemUpdateInput object must contain the following attributes:

Attribute Data Type Description
cart_item_id Int! The unique ID assigned when a customer places an item in the cart
quantity Float! The new quantity of the item. A value of 0 removes the item from the cart

Output attributes

The UpdateCartItemsOutput object contains the Cart object.

Attribute Data Type Description
cart Cart! Describes the contents of the specified shopping cart

Cart object

Attribute Data Type Description
applied_coupon AppliedCoupon The AppliedCoupon object contains the code text attribute, which specifies the coupon code
available_payment_methods AvailablePaymentMethod Available payment methods
billing_address BillingCartAddress Contains the billing address specified in the customer’s cart
email String The customer’s email address
items CartItemInterface Contains the items in the customer’s cart
prices CartPrices Contains subtotals and totals
selected_payment_method SelectedPaymentMethod Selected payment method
shipping_addresses ShippingCartAddress Contains one or more shipping addresses

Cart query output provides more information about the Cart object.