RemoveGiftCardFromCartMutation
Description
Removes a previously applied gift card from the cart. This mutation allows you to cancel a gift card that was applied using the applyGiftCardToCart mutation.
Endpoint
mutation removeGiftCardFromCart($cartId: String!, $code: String!) {
removeGiftCardFromCart(cartId: $cartId, code: $code) {
# Return fields
}
}
Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
| cartId | String | Yes | The unique identifier of the cart from which the gift card will be removed. This ID is obtained from createGuestCart or createCustomerCart mutations. |
| code | String | Yes | The gift card code to remove from the cart. This should match the code that was previously applied. |
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. |
| 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, with any discounts from the removed gift card no longer applied. |
For detailed information about the structure of these fields, refer to the CartQuery documentation.
Usage Example
mutation {
removeGiftCardFromCart(
cartId: "abc123",
code: "GC12345678"
) {
items {
id
quantity
name
row_total {
value
currency
}
}
totals {
grand_total {
value
currency
}
gift_card_amount {
value
currency
}
}
}
}
Example Response
{
"data": {
"removeGiftCardFromCart": {
"items": [
{
"id": "123",
"quantity": 2,
"name": "Sample Product",
"row_total": {
"value": 39.98,
"currency": "USD"
}
}
],
"totals": {
"grand_total": {
"value": 39.98,
"currency": "USD"
},
"gift_card_amount": {
"value": 0,
"currency": "USD"
}
}
}
}
}
Notes
- If the gift card code is not currently applied to the cart, an error may be thrown.
- After removing a gift card, the cart totals will be recalculated without the gift card amount.
- You can apply a different gift card to the cart after removing the current one by using the
applyGiftCardToCartmutation. - This mutation requires the exact gift card code that was previously applied to the cart.
- If multiple gift cards are applied to the cart, this mutation will only remove the specified gift card.