Unit Conversion API

The Unit Conversion API converts between different units of measurement.

/v1/unitconversion GET

https://api.api-ninjas.com/v1/unitconversion

Returns conversions between different units of the same measurement type.


Parameters

  • amount  required

    The numerical value to convert.

  • unit  required

    The source unit to convert from. Spaces should be replaced with underscores. See Supported Measurement Types for a list of available units.

Headers

  • X-Api-Key  required

    API Key associated with your account.

Response

Returns a JSON object with the following properties:

  • type  required

    The measurement type (e.g., length, volume, temperature, etc.).

  • unit  required

    The source unit that was converted from.

  • amount  required

    The original amount to convert.

  • conversions  required

    An object containing all the converted values for each unit of the same measurement type.

Supported Measurement Types

The API supports the following measurement types and units:

  • Length

    meter, kilometer, centimeter, millimeter, micrometer, nanometer, mile, yard, foot, inch, nautical_mile, furlong, light_year, astronomical_unit

  • Volume

    cubic_meter, liter, milliliter, gallon, quart, pint, cup, fluid_ounce, tablespoon, teaspoon, cubic_foot, cubic_inch, cubic_centimeter, cubic_millimeter

  • Area

    square_meter, square_kilometer, square_centimeter, square_millimeter, square_mile, square_yard, square_foot, square_inch, acre, hectare

  • Temperature

    celsius, fahrenheit, kelvin

  • Weight

    kilogram, gram, milligram, metric_ton, pound, ounce, stone, us_ton, imperial_ton, carat

  • Time

    second, millisecond, microsecond, nanosecond, minute, hour, day, week, month, year, decade, century

  • Speed

    meter_per_second, kilometer_per_hour, mile_per_hour, knot, foot_per_second

  • Force

    newton, kilonewton, pound_force, dyne

  • Power

    watt, kilowatt, megawatt, horsepower, btu_per_hour

  • Pressure

    pascal, kilopascal, megapascal, bar, psi, atmosphere, torr, millimeter_of_mercury

  • Energy

    joule, kilojoule, calorie, kilocalorie, watt_hour, kilowatt_hour, electron_volt, british_thermal_unit, us_therm, foot_pound

Sample Request Live Demo!

amount
unit
https://api.api-ninjas.com/v1/unitconversion?amount=5&unit=meter

Headers

X-Api-KeyLog in or sign up to get your API Key

Sample Response

JSON
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 { "type": "length", "unit": "meter", "amount": 5, "conversions": { "meter": 5, "kilometer": 0.005, "centimeter": 500, "millimeter": 5000, "micrometer": 5000000, "nanometer": 5000000000, "mile": 0.00310686, "yard": 5.46806649, "foot": 16.4041995, "inch": 196.850394, "nautical_mile": 0.00269978, "furlong": 0.02485485, "light_year": 0, "astronomical_unit": 0 } }

Code Examples

1 2 3 4 5 6 7 8 import requests api_url = 'https://api.api-ninjas.com/v1/unitconversion?amount=5&unit=meter' response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY'}) if response.status_code == requests.codes.ok: print(response.text) else: print("Error:", response.status_code, response.text)

If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.