Skip to main content

Apply a discount code to the cart

Add an action code (discount code) to the cart and get the updated totals with the discount applied.

Mutation

mutation ApplyActionCode($cartId: String!, $actionCode: String!) {
cartAddActionCode(
id: $cartId
input: { actionCode: $actionCode }
) {
actionCode
total {
subTotal
totalGross
totalNet
discount
discountNet
}
}
}

Variables

{
"cartId": "019c77b7-565f-7ea0-8660-42bc63a7f728",
"actionCode": "SUMMER20"
}

Response

{
"data": {
"cartAddActionCode": {
"actionCode": "SUMMER20",
"total": {
"subTotal": 4785.12,
"totalGross": 5120.12,
"totalNet": 6195.34,
"discount": 957.02,
"discountNet": 1157.99
}
}
}
}

How it works

The actionCode goes inside the input object. If the code is invalid or cannot be applied, the mutation returns an error — check for CART_ACTION_CODE_ADD_ERROR in the response extensions. The actionCode field on the cart is only populated when a valid code is active. The discount and discountNet fields on the total reflect the reduction. To remove an applied code, use the cartDeleteActionCode mutation.

See also