Apply/remove discount codes
Use the applyDiscountToCart and removeDiscountFromCart mutations to apply or remove eligible discounts from a cart before finalizing a purchase. Marketplace Managers create and manage discounts. For more information on discounts, refer to the help.
Mutation:
mutation applyDiscountToCart($input: ApplyDiscountInput!){
applyDiscountToCart(input: $input) {
cart {
id
items {
id
product {
name
}
discounts {
id
code
}
}
pricingTotal {
amountDueAfterTax
totalTaxAmount
}
}
}
}
b. mutation removeDiscountFromCart($input: RemoveDiscountCodeInput!){
removeDiscountFromCart(input: $input){
cart {
id
items {
id
product {
name
}
}
pricingTotal {
amountDueAfterTax
totalTaxAmount
}
}
}
}
Sample arguments
{
"input":{
"cartId": "95cce1ea-37fb-431d-9f5a-7df387b7e8e4",
"discountCode": "FLAT_50_OFF"
}
}
Sample output
{ "data": {
"applyDiscountToCart": {
"cart": {
"id": "6512b7ff875fe104e5fde6da",
"items": [
{
"id": "b7ec8290-d984-4608-bca6-f31191e61f05",
"product": {
"name": "Tag and Track device 1"
},
"discounts": [{
"id": "33ec8290-d984-4608-bca3-f31191e61f12",
"code": "FLAT_50_OFF
}]
},
{
"id": "5dc0fe86-b66c-450d-bd6b-9c4a5e19e061",
"product": {
"name": "Stacked Web App (DO NOT EDIT OR CHANGE)"
},
"discounts": []
}
],
"pricingTotal": {
"amountDueAfterTax": 474.1,
"totalTaxAmount": 34.1
}
}
}
}
}
Error handling:
The above mentioned mutations for discounts return errors if a request is made with invalid data or headers. For more information on errors and how to handle them, refer to. The applyDiscontToCart
can result in an error of type InvalidDiscountCodeError
, if an invalid discount is provided as input.
Example
Arguments:
{
"input": {
"cartId": "6512b7ff875fe104e5fde6da",
"discountCode": "RANDOM_DISCOUNT"
}
}
Output:
{
"data": {
"applyDiscountToCart": {
"cart": null,
"userErrors": [
{
"__typename": "InvalidDiscountCodeError",
"message": "Discount RANDOM_DISCOUNT does not exist or is expired.",
"path": [
"input",
"discountCode"
]
}
]
}
}
}
Was this page helpful?
Tell us more…
Help us improve our content. Responses are anonymous.
Thanks
We appreciate your feedback!