
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 aprice, a percentagediscount, an optionalsecondDiscountand an optionaltaxRate, and returns the sale price, the savings and the total with tax.original-price: takes asalePriceand 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%.
effectiveDiscountPercentgives the combined figure. - Sales tax is charged on the discounted price.
fullPriceWithTaxis what the full price would have cost with tax. - Money in the response is rounded to the cent.
original-pricereturns 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-calculatorCalculate a sale price after one or two discounts, or work back to the original price
Request Body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
| operation | string Enum: sale-price, original-price | Optional | What to calculate.Default: sale-price |
| price | number | Optional | Original price. Required for sale-price. |
| salePrice | number | Optional | Price after the discount. Required for original-price. |
| discount | number | Required | Percentage off, 0 to 100. |
| secondDiscount | number | Optional | A second percentage off, taken from the already-reduced price. 0 to 100.Default: 0 |
| taxRate | number | Optional | Sales 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 key403
Forbidden - The API key is inactive or expired, or the request IP is not allowed405
Method Not Allowed - This endpoint accepts GET and POST only429
Too Many Requests - Rate limit exceeded (120 requests per minute per API key)500
Internal Server ErrorGET
https://opentools.ca/api/v1/tools/discount-calculatorCalculate 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
| Parameter | Type | Required | Description |
|---|---|---|---|
| operation | string Enum: sale-price, original-price | Optional | What to calculate.Default: sale-price |
| price | number | Optional | Original price. Required for sale-price. |
| salePrice | number | Optional | Price after the discount. Required for original-price. |
| discount | number | Required | Percentage off, 0 to 100. |
| secondDiscount | number | Optional | A second percentage off, taken from the already-reduced price. 0 to 100.Default: 0 |
| taxRate | number | Optional | Sales 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 key403
Forbidden - The API key is inactive or expired, or the request IP is not allowed405
Method Not Allowed - This endpoint accepts GET and POST only429
Too Many Requests - Rate limit exceeded (120 requests per minute per API key)500
Internal Server ErrorCode 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"Rather use it in your browser? Open the Discount Calculator