Skip to main content
Version: 2.0.0

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

ArgumentTypeRequiredDescription
cartIdStringYesThe unique identifier of the cart from which the gift card will be removed. This ID is obtained from createGuestCart or createCustomerCart mutations.
codeStringYesThe 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:

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.
selected_shipping_methodObjectThe selected shipping method for the cart.
selected_payment_methodObjectThe selected payment method for the cart.
totalsObjectCart 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 applyGiftCardToCart mutation.
  • 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.