The Unit Conversion API converts between different units of measurement.
https://api.api-ninjas.com/v1/unitconversion
Returns conversions between different units of the same measurement type.
amount
requiredThe numerical value to convert.
unit
requiredThe source unit to convert from. Spaces should be replaced with underscores. See Supported Measurement Types for a list of available units.
X-Api-Key
requiredAPI Key associated with your account.
Returns a JSON object with the following properties:
type
requiredThe measurement type (e.g., length, volume, temperature, etc.).
unit
requiredThe source unit that was converted from.
amount
requiredThe original amount to convert.
conversions
requiredAn object containing all the converted values for each unit of the same measurement type.
The API supports the following measurement types and units:
meter, kilometer, centimeter, millimeter, micrometer, nanometer, mile, yard, foot, inch, nautical_mile, furlong, light_year, astronomical_unit
cubic_meter, liter, milliliter, gallon, quart, pint, cup, fluid_ounce, tablespoon, teaspoon, cubic_foot, cubic_inch, cubic_centimeter, cubic_millimeter
square_meter, square_kilometer, square_centimeter, square_millimeter, square_mile, square_yard, square_foot, square_inch, acre, hectare
celsius, fahrenheit, kelvin
kilogram, gram, milligram, metric_ton, pound, ounce, stone, us_ton, imperial_ton, carat
second, millisecond, microsecond, nanosecond, minute, hour, day, week, month, year, decade, century
meter_per_second, kilometer_per_hour, mile_per_hour, knot, foot_per_second
newton, kilonewton, pound_force, dyne
watt, kilowatt, megawatt, horsepower, btu_per_hour
pascal, kilopascal, megapascal, bar, psi, atmosphere, torr, millimeter_of_mercury
joule, kilojoule, calorie, kilocalorie, watt_hour, kilowatt_hour, electron_volt, british_thermal_unit, us_therm, foot_pound
https://api.api-ninjas.com/v1/unitconversion?amount=5&unit=meter
Headers
X-Api-Key
Log in or sign up to get your API Key
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
}
}
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.