Discount Calculation
Finance Math & Calculations Credits / request: 1Applies a percent or fixed discount to a list price.
GET
https://api.apikodu.com/api/v1/math/discount
Documentation
Overview
Calculates discount (percent or fixed amount).
Authentication
Every request requires the x-api-key header. Credits used and remaining quota are returned in response headers (x-api-credits-used, x-api-remaining-credits, x-rate-limit-*).
Request
GET
https://api.apikodu.com/api/v1/math/discount?amount=100&mode=percent&rate=10¤cy=EUR
GET query or POST JSON (single amount or list).
Parameters
| Name | Type | Required | Default | Options | Description |
|---|---|---|---|---|---|
amount |
number | * Required | — | — | List price (GET). POST uses amount or items. |
mode |
string | Optional | percent |
percent fixed |
percent or fixed. |
rate |
number | Optional | — | — | Rate for percent mode. |
amountDiscount |
number | Optional | — | — | Discount amount for fixed mode. |
currency |
string | Optional | — | — | ISO code. |
Response
| Name | Type | Description |
|---|---|---|
amountList |
number | List price before discount. 2 decimals. |
amountDiscount |
number | Total discount amount. Sum of steps when stacked. |
amountNet |
number | Amount payable after discount. |
savingPercent |
number | Saving percent = amountDiscount / amountList * 100. |
currency |
string | ISO currency code. Null if omitted. |
breakdown |
array | Each applied discount step. One step on GET. |
breakdown[].index |
integer | Step index (1-based). |
breakdown[].mode |
string | Step mode: percent or fixed. |
breakdown[].amountBefore |
number | Amount before this step. |
breakdown[].amountDiscount |
number | Discount applied in this step. |
breakdown[].amountAfter |
number | Amount after this step. |
Errors
| HTTP | code | Description |
|---|---|---|
400 |
-241 |
amount missing/out of range, POST body missing, or amountDiscount negative in fixed mode. |
400 |
-242 |
mode is not percent or fixed. |
401 |
-100 |
x-api-key is missing, empty, malformed, inactive, banned, expired, IP-restricted, or not allowed for this API. |
429 |
-221 |
Per-minute request limit exceeded. Response headers: x-rate-limit-limit, x-rate-limit-remaining, x-rate-limit-reset. |
429 |
— | Package credit quota cannot cover this request. Body may be { error, limit, currentUsage, requestCost } (no code field). |
500 |
-1 |
Unexpected server error. message is a generic error text without technical details. |
Notes
- Success body is { data: { ... } }. Error body is { code, message }. code is an ApiResponseCode enum value (negative integer).
- POST /discount accepts the same fields in the body.
Sample response
{
"data": {
"amountList": 100.00,
"amountDiscount": 10.00,
"amountNet": 90.00,
"savingPercent": 10.0,
"currency": "EUR",
"breakdown": [
{
"index": 1,
"mode": "percent",
"amountBefore": 100.00,
"amountDiscount": 10.00,
"amountAfter": 90.00
}
]
}
}
Code samples
const response = await fetch('https://api.apikodu.com/api/v1/math/discount', {
method: 'GET',
headers: {
'x-api-key': 'YOUR_API_KEY'
}
});
const data = await response.json();
console.log(data);
import requests
headers = {
'x-api-key': 'YOUR_API_KEY'
}
response = requests.get('https://api.apikodu.com/api/v1/math/discount', headers=headers)
print(response.json())
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");
var response = await client.GetStringAsync("https://api.apikodu.com/api/v1/math/discount");
Console.WriteLine(response);
$response = file_get_contents('https://api.apikodu.com/api/v1/math/discount', false, stream_context_create([
'http' => [
'header' => "x-api-key: YOUR_API_KEY"
]
]));
print_r(json_decode($response, true));
curl -X GET 'https://api.apikodu.com/api/v1/math/discount' \
-H 'x-api-key: YOUR_API_KEY'
Start building in minutes
Create a free account, get your API key and send your first request in minutes.