Skip to main content

applyDiscountCode

Requires a customer (portal or buyer app) session.

Applies a discount code to the cart, or clears it with a null or blank code. The bill and checkout then price with it. A code that gives this cart nothing is refused with DISCOUNT_CODE_NOT_APPLICABLE, whatever the reason.

Errors: a failed call returns a GraphQL errors entry, not a field on the result, and data may be null or partial. Read the entry's extensions.code and message; every shape and code is in the Error reference.

Example:

mutation ApplyDiscountCode($input: ApplyDiscountCodeInput!) {
applyDiscountCode(input: $input) {
id
discountCode
name
itemCount
revision
subtotal
items {
id
createdAt
acceptAlternativeIfUnavailable
baseUnitPrice
customFields
lineTotal
}
}
}

Variables:

{
"input": {}
}

Response:

{
"data": {
"applyDiscountCode": {
"id": "id",
"discountCode": "string",
"name": "string",
"itemCount": 0,
"revision": 0,
"subtotal": 0,
"items": [
{
"id": "id",
"createdAt": "2025-01-15T00:00:00Z",
"acceptAlternativeIfUnavailable": true,
"baseUnitPrice": 0,
"customFields": {},
"lineTotal": 0
}
]
}
}
}
applyDiscountCode(
input: ApplyDiscountCodeInput!
): CartType!

Arguments​

applyDiscountCode.input ● ApplyDiscountCodeInput! non-null input​

The code, the expected cart revision and the operation ID.

Type​

CartType object​

The customer's cart.