updateCartItems mutation

The updateCartItems mutation allows you to modify items in the specified cart. You can also replace the current quantity of one or more cart items with the specified quantities. The mutation 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
29
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 attributes

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 attributes

The CartItemUpdateInput object can 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
customizable_options [CustomizableOptionInput!] An array that defines customizable options for the product
gift_message GiftMessageInput Gift message details for the cart item
gift_wrapping_id ID The unique identifier of the gift wrapping to be used for the cart item
quantity Float The new quantity of the item. A value of 0 removes the item from the cart

CustomizableOptionInput attributes

The CustomizableOptionInput object must contain the following attributes.

Attribute Data Type Description
id Int! A unique ID assigned to the customizable option
value_string String! A value assigned to the customizable option

GiftMessageInput attributes

The GiftMessageInput object must contain the following attributes.

Attribute Data Type Description
from String! The name of the gift sender
message String! The text of the gift message
to String! The name of the gift recipient

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 Deprecated. Use applied_coupons instead
applied_coupons [AppliedCoupon] An array of AppliedCoupon objects. Each object contains the code text attribute, which specifies the coupon code
applied_gift_cards [AppliedGiftCard] An array of AppliedGiftCard objects. An AppliedGiftCard object contains the code text attribute, which specifies the gift card code. applied_gift_cards is a Commerce-only attribute, defined in the GiftCardAccountGraphQl module
applied_reward_points RewardPointsAmount The amount of reward points applied to the cart
applied_store_credit AppliedStoreCredit Contains store credit information applied to the cart. applied_store_credit is a Commerce-only attribute, defined in the CustomerBalanceGraphQl module
available_gift_wrappings [GiftWrapping]! The list of available gift wrapping options for the cart
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
gift_message GiftMessage A gift message added to the cart
gift_receipt_included Boolean! Indicates if the customer requested a gift receipt for the cart
gift_wrapping GiftWrapping The selected gift wrapping for the cart
id ID! The ID of the cart
is_virtual Boolean! Indicates whether the cart contains only virtual products
items [CartItemInterface] Contains the items in the customer’s cart
prices CartPrices Contains subtotals and totals
printed_card_included Boolean! Indicates if the customer requested a printed card for the cart
selected_payment_method SelectedPaymentMethod Selected payment method
shipping_addresses [ShippingCartAddress]! Contains one or more shipping addresses
total_quantity Float! Total Quantity of products in the cart

Cart query output provides more information about the Cart object.

Errors

Error Description
Could not find cart item with id: XXX The specified input.cart_items.cart_item_id value does not exist in the quote_item database table.
Could not find a cart with ID "XXX" The specified cart_id value does not exist in the quote_id_mask database table.
Required parameter "cart_id" is missing. The value specified in the cart_id argument is empty.
Required parameter "cart_items" is missing. The cart_items argument is empty, or its value is specified as a non-array value.
Required parameter "quantity" for "cart_items" is missing. The required input.cart_items.quantity argument must be specified.
The current user cannot perform operations on cart "XXX" An unauthorized user (guest) tried to update a customer’s cart, or an authorized user (customer) tried to update the cart of another customer.