removeItemFromCart mutation

The removeItemFromCart mutation deletes the entire quantity of a specified item from the cart. If you remove all items from the cart, the cart continues to exist.

Syntax

mutation: {removeItemFromCart(input: RemoveItemFromCartInput): {RemoveItemFromCartOutput}}

Example usage

The following example removes cart item 14 from the cart.

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
mutation {
  removeItemFromCart(
    input: {
      cart_id: "IeTUiU0oCXjm0uRqGCOuhQ2AuQatogjG",
      cart_item_id: 14
    }
  ){
  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
{
  "data": {
    "removeItemFromCart": {
      "cart": {
        "items": [
          {
            "id": "13",
            "product": {
              "name": "Strive Shoulder Pack"
            },
            "quantity": 3
          }
        ],
        "prices": {
          "grand_total": {
            "value": 96,
            "currency": "USD"
          }
        }
      }
    }
  }
}

Input attributes

RemoveItemFromCartInput object

The RemoveItemFromCartInput object must contain the following attributes:

Attribute Data Type Description
cart_id String! The unique ID that identifies the customer’s cart
cart_item_id Int! The unique ID assigned when a customer places an item in the cart

Output attributes

The RemoveItemFromCartOutput 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
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_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_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.