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, andapprox 5 kg. A range such as10-12 cmis 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.99in one currency of your choice. No currency conversion happens; convert first with Currency if offers differ. -
perchooses the comparison unit (default is the category base unit, such as litres for volume).localereads quantities such as1,5 l. -
Rank 1 is cheapest and equal prices share a rank. Without
decimals, unit prices keep full precision.premium_percentalways 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.