UnifyUnits Developers

Unit price

POST /v1/unit-price answers "which is the better deal?" for offers sold in different sizes. Send each offer's price and quantity as written; the API normalizes the quantities, computes the exact price per unit, and ranks the offers.

Example

bash
curl "https://api.unifyunits.com/v1/unit-price" \
  -X POST \
  -H "Authorization: Bearer $UNIFYUNITS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"offers":[{"price":"4.99","quantity":"750 ml"},{"price":"6.49","quantity":"1 l"}],"decimals":2}'

The 1 l bottle costs 6.49 per litre and the 750 ml bottle 6.65, so the larger one ranks first and the smaller costs 2.52% more (premium_percent).

Rules

  • Quantities use the same forms as Normalize: 750 ml, 6 x 330 ml, 1 lb 4 oz, and approx 5 kg. A range such as 10-12 cm is rejected because it is not one amount.
  • All offers must measure the same kind of thing (all volume, all mass, and so on). Temperature and other non-additive units cannot be priced.
  • Prices are positive decimal strings such as 4.99 in one currency of your choice. No currency conversion happens; convert first with Currency if offers differ.
  • per chooses the comparison unit (default is the category base unit, such as litres for volume). locale reads quantities such as 1,5 l.
  • Rank 1 is cheapest and equal prices share a rank. Without decimals, unit prices keep full precision. premium_percent always has two decimal places.
  • Two to fifty offers per request.
  • Requires the Developer plan or higher. A successful request uses one conversion from your monthly quota per offer; a failed request is free.