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
| Argument | Type | Required | Description |
|---|---|---|---|
| cartId | String | Yes | The unique identifier of the cart from which the item will be removed. This ID is obtained from createGuestCart or createCustomerCart mutations. |
| itemId | Int | Yes | The 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:
| Field | Type | Description |
|---|---|---|
| billing_address | Object | The billing address associated with the cart. |
| shipping_address | Object | The shipping address associated with the cart. |
| items | [CartItem] | Array of items in the cart, with the removed item no longer present. |
| selected_shipping_method | Object | The selected shipping method for the cart. |
| selected_payment_method | Object | The selected payment method for the cart. |
| totals | Object | Cart 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
updateCartItemsmutation instead. - If you want to clear all items from the cart, use the
clearCartmutation instead.