calculateVariantPrice
Requires permission products:pricing:read.
Returns the unit price of a variant for a quantity, taken from the best matching quantity tier in the base currency, or from the variant's base price when no tier matches. The result also carries the original price and the discount against it. Needs the pricing read permission.
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 CalculateVariantPrice($quantity: Int!, $variantId: ID!) {
calculateVariantPrice(quantity: $quantity, variantId: $variantId) {
tierName
discount
isValid
originalPrice
price
}
}
curl -X POST "https://<api-host>/graphql" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
--data @- <<'EOF'
{
"query": "query CalculateVariantPrice($quantity: Int!, $variantId: ID!) {\n calculateVariantPrice(quantity: $quantity, variantId: $variantId) {\n tierName\n discount\n isValid\n originalPrice\n price\n }\n}",
"variables": {
"quantity": 0,
"variantId": "id"
}
}
EOF
Variables:
{
"quantity": 0,
"variantId": "id"
}
Response:
{
"data": {
"calculateVariantPrice": {
"tierName": "string",
"discount": 0,
"isValid": true,
"originalPrice": 0,
"price": 0
}
}
}
calculateVariantPrice(
customerTier: String
quantity: Int!
variantId: ID!
): CalculatedPrice!
Arguments
calculateVariantPrice.customerTier ● String scalar
The customer tier to price for. When given, only tiers that list this customer tier apply.
calculateVariantPrice.quantity ● Int! non-null scalar
The quantity to price. Tiers apply by their minimum and maximum quantity.
calculateVariantPrice.variantId ● ID! non-null scalar
The ID of the variant.
Type
CalculatedPrice object
The price worked out for a quantity, after any tier applies.