applyGiftCardToCart mutation
Magento Commerce only
The content on this page is for Magento Commerce only.
Learn more
The applyGiftCardToCart
mutation applies a pre-defined gift card code to the specified cart.
Syntax
mutation: applyGiftCardToCart(input: ApplyGiftCardToCartInput): ApplyGiftCardToCartOutput
Example usage
The following example adds a gift card with the code 0330CEIVTLB4
to the cart. The gift card has a value of $20.
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 {
applyGiftCardToCart(
input: {
cart_id: "lY8PnKhlHBGc4WS5v0Y3dWjxiA5PvvgY"
gift_card_code: "0330CEIVTLB4"
}
) {
cart {
applied_gift_cards {
applied_balance {
value
currency
}
code
current_balance {
value
currency
}
expiration_date
}
}
}
}
Response:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"data": {
"applyGiftCardToCart": {
"cart": {
"applied_gift_cards": [
{
"applied_balance": {
"value": 20,
"currency": "USD"
},
"code": "0330CEIVTLB4",
"current_balance": {
"value": 20,
"currency": "USD"
},
"expiration_date": null
}
]
}
}
}
}
Input attributes
The applyGiftCardToCart
mutation requires the cart_id
and gift_card_code
.
ApplyGiftCardToCartInput object
The ApplyGiftCardToCartInput
object must contain the following attributes:
Attribute | Data Type | Description |
---|---|---|
cart_id |
String! | The unique ID that identifies the customer’s cart |
gift_card_code |
String! | The gift card code |
Output attributes
The ApplyGiftCardToCartOutput
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 |
Deprecated. Use applied_coupons instead |
applied_coupons |
[AppliedCoupon ] |
An array of AppliedCoupon objects. Each 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_reward_points |
RewardPointsAmount |
The amount of reward points applied to the cart |
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_gift_wrappings |
[GiftWrapping]! | The list of available gift wrapping options for the cart |
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 |
gift_message |
GiftMessage | A gift message added to the cart |
gift_receipt_included |
Boolean! | Indicates if the customer requested a gift receipt for the cart |
gift_wrapping |
GiftWrapping | The selected gift wrapping for the cart |
id |
ID! | The ID of the cart |
is_virtual |
Boolean! | Indicates whether the cart contains only virtual products |
items |
[CartItemInterface] | Contains the items in the customer’s cart |
prices |
CartPrices | Contains subtotals and totals |
printed_card_included |
Boolean! | Indicates if the customer requested a printed card for the cart |
selected_payment_method |
SelectedPaymentMethod | Selected payment method |
shipping_addresses |
[ShippingCartAddress]! | Contains one or more shipping addresses |
total_quantity |
Float! | Total Quantity of products in the cart |
Cart query output provides more information about the Cart
object.
Errors
Error | Description |
---|---|
The gift card code couldn't be added. Verify your information and try again. |
The specified gift_card_code is incorrect. |
Could not find a cart with ID "XXX" |
The specified cart_id value does not exist in the quote_id_mask table. |
Field ApplyGiftCardToCartInput.gift_card_code of required type String! was not provided. |
The required field gift_card_code was not provided. |
Required parameter \"gift_card_code\" is missing |
The value provided in the field gift_card_code is empty. |
Field ApplyGiftCardToCartInput.cart_id of required type String! was not provided. |
The required field cart_id was not provided. |
Required parameter \"cart_id\" is missing |
The value provided in the field cart_id is empty. |