Margin & Markup Calculator

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.
  • multiplier is price divided by cost.

Notes

  • cost, price and profit are dollar amounts. margin and markup are 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, markupPercent and multiplier are null when 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-calculator
Solve cost, price, profit, margin and markup from any two of them

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
cost
number
OptionalWhat the item cost, 0 or more.
price
number
OptionalSelling price, 0 or more.
profit
number
OptionalPrice minus cost. Negative for a loss.
margin
number
OptionalProfit as a percentage of the selling price.
markup
number
OptionalProfit 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 solved
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 POST only
429
Too Many Requests - Rate limit exceeded (120 requests per minute per API key)
500
Internal Server Error

Code 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
}'

Ready to get started?

Create an API key to start using the Margin & Markup Calculator API.

Rather use it in your browser? Open the Margin & Markup Calculator