Discount Calculator

Discount Calculator API

Finance

Find the sale price and how much you save from a percentage off, stack a second discount, add sales tax, or work back to the original price from a sale price.

Authentication

Send your API key as a Bearer token in the Authorization header (Authorization: Bearer YOUR_API_KEY), or in an X-API-Key header.

Rate Limit

120 requests per minute

Endpoints

2 endpoints available

Overview

Two operations, chosen by operation:

  • sale-price (default): takes a price, a percentage discount, an optional secondDiscount and an optional taxRate, and returns the sale price, the savings and the total with tax.
  • original-price: takes a salePrice and the discount or discounts that were applied, and returns the price before the discount.

Notes

  • Discounts are percentages from 0 to 100 (25 means 25% off).
  • Two discounts multiply. 20% off and then an extra 10% off is 28% off in total, not 30%. effectiveDiscountPercent gives the combined figure.
  • Sales tax is charged on the discounted price. fullPriceWithTax is what the full price would have cost with tax.
  • Money in the response is rounded to the cent.
  • original-price returns a 400 error when the discounts add up to 100% off, because the original price cannot be recovered.

Endpoints

POST
https://opentools.ca/api/v1/tools/discount-calculator
Calculate a sale price after one or two discounts, or work back to the original price

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
operation
string
Enum: sale-price, original-price
OptionalWhat to calculate.Default: sale-price
price
number
OptionalOriginal price. Required for sale-price.
salePrice
number
OptionalPrice after the discount. Required for original-price.
discount
number
Required
Percentage off, 0 to 100.
secondDiscount
number
OptionalA second percentage off, taken from the already-reduced price. 0 to 100.Default: 0
taxRate
number
OptionalSales tax percentage added after the discounts. sale-price only.Default: 0

Response Example

{
  "success": true,
  "operation": "sale-price",
  "originalPrice": 120,
  "priceAfterFirstDiscount": 96,
  "firstDiscountSaving": 24,
  "secondDiscountSaving": 9.6,
  "salePrice": 86.4,
  "savings": 33.6,
  "effectiveDiscountPercent": 28,
  "tax": 11.23,
  "finalPrice": 97.63,
  "fullPriceWithTax": 135.6
}

Error Codes

400
Bad Request - A field is missing or invalid. The response lists each problem.
401
Unauthorized - Missing or invalid API key
403
Forbidden - The API key is inactive or expired, or the request IP is not allowed
405
Method Not Allowed - This endpoint accepts GET and POST only
429
Too Many Requests - Rate limit exceeded (120 requests per minute per API key)
500
Internal Server Error
GET
https://opentools.ca/api/v1/tools/discount-calculator
Calculate a sale price after one or two discounts, or work back to the original price. Same fields as the POST body, sent as query parameters.

Query Parameters

ParameterTypeRequiredDescription
operation
string
Enum: sale-price, original-price
OptionalWhat to calculate.Default: sale-price
price
number
OptionalOriginal price. Required for sale-price.
salePrice
number
OptionalPrice after the discount. Required for original-price.
discount
number
Required
Percentage off, 0 to 100.
secondDiscount
number
OptionalA second percentage off, taken from the already-reduced price. 0 to 100.Default: 0
taxRate
number
OptionalSales tax percentage added after the discounts. sale-price only.Default: 0

Response Example

{
  "success": true,
  "operation": "sale-price",
  "originalPrice": 120,
  "priceAfterFirstDiscount": 96,
  "firstDiscountSaving": 24,
  "secondDiscountSaving": 9.6,
  "salePrice": 86.4,
  "savings": 33.6,
  "effectiveDiscountPercent": 28,
  "tax": 11.23,
  "finalPrice": 97.63,
  "fullPriceWithTax": 135.6
}

Error Codes

400
Bad Request - A field is missing or invalid. The response lists each problem.
401
Unauthorized - Missing or invalid API key
403
Forbidden - The API key is inactive or expired, or the request IP is not allowed
405
Method Not Allowed - This endpoint accepts GET and POST only
429
Too Many Requests - Rate limit exceeded (120 requests per minute per API key)
500
Internal Server Error

Code Examples

# Two stacked discounts with tax
curl -X POST https://opentools.ca/api/v1/tools/discount-calculator \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "operation": "sale-price",
  "price": 120,
  "discount": 20,
  "secondDiscount": 10,
  "taxRate": 13
}'

# Original price from a sale price
curl -X POST https://opentools.ca/api/v1/tools/discount-calculator \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "operation": "original-price",
  "salePrice": 72,
  "discount": 25
}'

# The same request as a GET with query parameters
curl "https://opentools.ca/api/v1/tools/discount-calculator?operation=sale-price&price=120&discount=20&secondDiscount=10&taxRate=13" \
  -H "Authorization: Bearer YOUR_API_KEY"

Ready to get started?

Create an API key to start using the Discount Calculator API.

Rather use it in your browser? Open the Discount Calculator