
Margin & Markup Calculator API
Finance
Enter any two of cost, selling price, profit, margin or markup and get the rest instantly, with a clear margin vs markup explanation and a conversion table.
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
1 endpoint available
Overview
Send exactly two of cost, price, profit, margin and markup, and it solves the rest. The valid pairs are cost with any other value, price with any other value, and profit with margin or markup. Margin plus markup is not valid.
Definitions
- Profit is price minus cost. It is negative for a loss.
- Margin is profit divided by price. Markup is profit divided by cost. A 30% markup is only a 23.08% margin.
multiplieris price divided by cost.
Notes
cost,priceandprofitare dollar amounts.marginandmarkupare percentages.- Money is worked in whole cents. When an amount is solved for, it is rounded to the cent, and profit is always price minus cost of the amounts returned. If the rounding nudges a percentage, a note says so. The percentage you sent is reported as you sent it.
- Impossible inputs get a 400 error with a plain explanation: a margin of 100% or more with a cost above zero, a cost of zero where markup has no value, or a loss bigger than the cost.
marginPercent,markupPercentandmultiplierarenullwhen they are undefined (a zero price or cost).- Dollar amounts can be up to 10 billion, and margin and markup within 1,000,000%.
Endpoints
POST
https://opentools.ca/api/v1/tools/margin-calculatorSolve cost, price, profit, margin and markup from any two of them
Request Body
Content-Type: application/json
| Parameter | Type | Required | Description |
|---|---|---|---|
| cost | number | Optional | What the item cost, 0 or more. |
| price | number | Optional | Selling price, 0 or more. |
| profit | number | Optional | Price minus cost. Negative for a loss. |
| margin | number | Optional | Profit as a percentage of the selling price. |
| markup | number | Optional | Profit as a percentage of the cost. |
Response Example
{
"success": true,
"mode": "cost-margin",
"cost": 60,
"price": 100,
"profit": 40,
"marginPercent": 40,
"markupPercent": 66.666667,
"multiplier": 1.666667,
"isLoss": false,
"notes": []
}Error Codes
400
Bad Request - Not exactly two fields given, an invalid pair, or inputs that cannot be solved401
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 POST only429
Too Many Requests - Rate limit exceeded (120 requests per minute per API key)500
Internal Server ErrorCode Examples
# Cost and margin
curl -X POST https://opentools.ca/api/v1/tools/margin-calculator \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"cost": 60,
"margin": 40
}'
# Price and markup
curl -X POST https://opentools.ca/api/v1/tools/margin-calculator \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"price": 100,
"markup": 30
}'Rather use it in your browser? Open the Margin & Markup Calculator