calculateDiscount
Requires at least one of the permissions payments:invoice:create, products:discount:read, purchase:purchase_order:create, purchase:purchase_order:update, sales:quote:create, sales:quote:update, sales:sales_invoice:create, sales:sales_order:create or sales:sales_order:update.
Works out the discount on an amount for a customer, product, variant or category, and saves nothing. The result carries the original price, the discount, the final price, the percentage and the schemes applied. Needs the discounts read permission, or permission to create or edit a quote, sales order, invoice or purchase order.
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
query CalculateDiscount($data: CalculateDiscountDto!) {
calculateDiscount(data: $data) {
appliedSchemes
discountAmount
discountPercentage
finalPrice
originalPrice
availableDiscounts {
id
code
name
type
discountAmount
fixedAmount
}
}
}
curl -X POST "https://<api-host>/graphql" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
--data @- <<'EOF'
{
"query": "query CalculateDiscount($data: CalculateDiscountDto!) {\n calculateDiscount(data: $data) {\n appliedSchemes\n discountAmount\n discountPercentage\n finalPrice\n originalPrice\n availableDiscounts {\n id\n code\n name\n type\n discountAmount\n fixedAmount\n }\n }\n}",
"variables": {
"data": {
"baseAmount": 0,
"quantity": 0
}
}
}
EOF
Variables:
{
"data": {
"baseAmount": 0,
"quantity": 0
}
}
Response:
{
"data": {
"calculateDiscount": {
"appliedSchemes": [
"string"
],
"discountAmount": 0,
"discountPercentage": 0,
"finalPrice": 0,
"originalPrice": 0,
"availableDiscounts": [
{
"id": "string",
"code": "string",
"name": "string",
"type": "string",
"discountAmount": 0,
"fixedAmount": 0
}
]
}
}
}
calculateDiscount(
data: CalculateDiscountDto!
): CalculateDiscountResult!
Arguments
calculateDiscount.data ● CalculateDiscountDto! non-null input
The base amount and quantity, and optionally the product, variant, category, customer, currency and region to match schemes against.
Type
CalculateDiscountResult object
The discount worked out on an amount.