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:
- GraphQL
- cURL
mutation ApplyDiscountCode($input: ApplyDiscountCodeInput!) {
applyDiscountCode(input: $input) {
id
discountCode
name
itemCount
revision
subtotal
items {
id
createdAt
acceptAlternativeIfUnavailable
baseUnitPrice
customFields
lineTotal
}
}
}
curl -X POST "https://<api-host>/graphql" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
--data @- <<'EOF'
{
"query": "mutation ApplyDiscountCode($input: ApplyDiscountCodeInput!) {\n applyDiscountCode(input: $input) {\n id\n discountCode\n name\n itemCount\n revision\n subtotal\n items {\n id\n createdAt\n acceptAlternativeIfUnavailable\n baseUnitPrice\n customFields\n lineTotal\n }\n }\n}",
"variables": {
"input": {}
}
}
EOF
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.