
Invoice Discount Calculator API
Find the discount that brings an invoice to a target grand total, after taxes and fees. Add line items, fees and taxes, enter the total you need, and get the exact % and amount.
Send your API key as a Bearer token in the Authorization header (Authorization: Bearer YOUR_API_KEY), or in an X-API-Key header.
120 requests per minute
1 endpoint available
Overview
Works backwards from the grand total you need. Send the line items, any fees and taxes, and a targetTotal. It returns the discount, as an amount and as a percentage of the discountable items, and the full invoice breakdown.
How the invoice is built
- Each line is quantity times unit price, rounded to the cent. The discount comes off the items marked
discountable(default true), before tax. Mark delivery or fixed charges as not discountable. - The share of the discount that comes off taxable items lowers the taxable amount.
- Fees are
fixed(a dollar amount),percent-subtotal(a percentage of the subtotal after the discount) orpercent-total(a percentage of the total after fees and tax, like a card surcharge, never taxed). Fees are taxable by default, exceptpercent-total. - Taxes are percentages. A
compoundtax is charged on the taxable amount plus the taxes listed before it. Sendtaxesor ataxPreset, not both. Presets:none,gst,hst-on,hst-ns,hst-15,qc,bc,mb,sk,vat-20. Rates change, so check them. - Every amount is rounded to the cent the way an invoice shows it, so the numbers match invoicing software.
Status
exact: a discount gives exactly the target.discountPercenthas just enough decimals that applying it to the discountable total and rounding to the cent gives backdiscountAmount.nearest: rounding makes the exact total impossible. You get the smallest discount at or under the target, andnextSmallerDiscount, which lands just over it.no-discount-needed: the invoice is already at or under the target (increaseNeededsays by how much).impossible: even a full discount of every discountable item leaves the total above the target (lowestPossibleTotal).nothing-discountable: no item can be discounted.
Limits: 200 items, 20 fees, 10 taxes. Quantity up to 100,000 and unit price up to 1,000,000.
Endpoints
https://opentools.ca/api/v1/tools/invoice-discount-calculatorRequest Body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
| items | array | Required | Line items, 1 to 200. |
| items[].description | string | Optional | Description, for your own reference. |
| items[].quantity | number | Required | Quantity, 0 to 100,000. |
| items[].unitPrice | number | Required | Unit price in dollars, 0 to 1,000,000. |
| items[].taxable | boolean | Optional | Whether tax applies to this item.Default: true |
| items[].discountable | boolean | Optional | Whether the discount may come off this item.Default: true |
| fees | array | Optional | Fees, up to 20.Default: [] |
| fees[].name | string | Optional | Fee name.Default: Fee |
| fees[].kind | string Enum: fixed, percent-subtotal, percent-total | Optional | How the fee is worked out.Default: fixed |
| fees[].value | number | Required | Dollars for a fixed fee, a percentage (3 for 3%) for the others. |
| fees[].taxable | boolean | Optional | Whether tax applies to this fee. Ignored for percent-total.Default: true |
| taxes | array | Optional | Taxes, up to 10. |
| taxes[].name | string | Optional | Tax name.Default: Tax |
| taxes[].rate | number | Required | Percentage, 0 to 100. |
| taxes[].compound | boolean | Optional | Charge this tax on the taxable amount plus the taxes before it.Default: false |
| taxPreset | string Enum: none, gst, hst-on, hst-ns, hst-15, qc, bc, mb, sk, vat-20 | Optional | A ready-made set of taxes. Use instead of taxes. |
| targetTotal | number | Required | The grand total you want, in dollars. |
Response Example
{
"success": true,
"status": "exact",
"targetTotal": 1000,
"withoutDiscount": {
"itemsTotal": 1190,
"discountableTotal": 1150,
"discount": 0,
"subtotal": 1190,
"fees": [],
"taxableAmount": 1190,
"taxes": [
{
"name": "HST",
"rate": 13,
"amount": 154.7
}
],
"surcharges": [],
"total": 1344.7
},
"discountAmount": 305.04,
"discountPercent": 26.525,
"invoice": {
"itemsTotal": 1190,
"discountableTotal": 1150,
"discount": 305.04,
"subtotal": 884.96,
"fees": [],
"taxableAmount": 884.96,
"taxes": [
{
"name": "HST",
"rate": 13,
"amount": 115.04
}
],
"surcharges": [],
"total": 1000
}
}Error Codes
Code Examples
# Discount an invoice down to $1,000
curl -X POST https://opentools.ca/api/v1/tools/invoice-discount-calculator \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"items": [
{
"description": "Design work",
"quantity": 10,
"unitPrice": 85
},
{
"description": "Printing",
"quantity": 250,
"unitPrice": 1.2
},
{
"description": "Delivery",
"quantity": 1,
"unitPrice": 40,
"discountable": false
}
],
"taxes": [
{
"name": "HST",
"rate": 13
}
],
"targetTotal": 1000
}'Rather use it in your browser? Open the Invoice Discount Calculator