Skip to main content
Version: 2.0.0

RemoveItemFromCartMutation

Description

Removes an item from the cart. This mutation allows you to delete a specific product from the cart based on its item ID.

Endpoint

mutation removeItemFromCart($cartId: String!, $itemId: Int!) {
removeItemFromCart(cartId: $cartId, itemId: $itemId) {
# Return fields
}
}

Arguments

ArgumentTypeRequiredDescription
cartIdStringYesThe unique identifier of the cart from which the item will be removed. This ID is obtained from createGuestCart or createCustomerCart mutations.
itemIdIntYesThe ID of the item to remove from the cart. This ID is returned in the cart items array when querying the cart.

Return Values

The mutation returns a CartType object with the following structure:

FieldTypeDescription
billing_addressObjectThe billing address associated with the cart.
shipping_addressObjectThe shipping address associated with the cart.
items[CartItem]Array of items in the cart, with the removed item no longer present.
selected_shipping_methodObjectThe selected shipping method for the cart.
selected_payment_methodObjectThe selected payment method for the cart.
totalsObjectCart totals information, recalculated after removing the item.

For detailed information about the structure of these fields, refer to the CartQuery documentation.

Usage Example

mutation {
removeItemFromCart(
cartId: "abc123",
itemId: 456
) {
items {
id
quantity
name
row_total {
value
currency
}
}
totals {
grand_total {
value
currency
}
}
}
}

Example Response

{
"data": {
"removeItemFromCart": {
"items": [
{
"id": "789",
"quantity": 1,
"name": "Another Product",
"row_total": {
"value": 29.99,
"currency": "USD"
}
}
],
"totals": {
"grand_total": {
"value": 29.99,
"currency": "USD"
}
}
}
}
}

Notes

  • The item is removed by setting its quantity to zero.
  • If the item ID is invalid or not present in the cart, an error may be thrown.
  • After removing an item, the cart totals will be recalculated.
  • If you want to update the quantity of an item rather than removing it, use the updateCartItems mutation instead.
  • If you want to clear all items from the cart, use the clearCart mutation instead.