Planets API

The Planets API provides key statistics for thousands of planets and exoplanets discovered in the known universe.

/v1/planets

HTTP GET

Get a list of planets matching specified parameters. Returns at most 30 results. To access more than 30 results, use the offset parameter to offset results in multiple API calls.

Parameters

At least one of the following parameters is required.

name (optional) - the name of the planet.

min_mass (optional) - minimum mass of the planet in Jupiters (1 Jupiter = 1.898 × 1027 kg).

max_mass (optional) - maximum mass of the planet in Jupiters (1 Jupiter = 1.898 × 1027 kg).

min_radius (optional) - minimum average radius of the planet in Jupiters (1 Jupiter = 69911 km).

max_radius (optional) - maximum average radius of the planet in Jupiters (1 Jupiter = 69911 km).

min_period (optional) - minimum orbital period of the planet in Earth days.

max_period (optional) - maximum orbital period of the planet in Earth days.

min_temperature (optional) - minimum average surface temperature of the planet in Kelvin.

max_temperature (optional) - maximum average surface temperature of the planet in Kelvin.

min_distance_light_year (optional) - minimum distance the planet is from Earth in light years.

max_distance_light_year (optional) - maximum distance the planet is from Earth in light years.

min_semi_major_axis (optional) - minimum semi major axis of planet in astronomical units (AU).

max_semi_major_axis (optional) - maximum semi major axis of planet in astronomical units (AU).

offset (optional) - number of results to offset for pagination.

Headers

X-Api-Key (required) - API Key associated with your account.

Sample Request URL

Live Demo!

https://api.api-ninjas.com/v1/planets?name=

Sample Response

[
  {
    "name": "Neptune",
    "mass": 0.0537,
    "radius": 0.346,
    "period": 59800,
    "semi_major_axis": 30.07,
    "temperature": 72,
    "distance_light_year": 0.000478,
    "host_star_mass": 1,
    "host_star_temperature": 6000
  }
]

import requests
name = 'Neptune'
api_url = 'https://api.api-ninjas.com/v1/planets?name={}'.format(name)
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)
var name = 'Neptune'
$.ajax({
    method: 'GET',
    url: 'https://api.api-ninjas.com/v1/planets?name=' + name,
    headers: { 'X-Api-Key': 'YOUR_API_KEY'},
    contentType: 'application/json',
    success: function(result) {
        console.log(result);
    },
    error: function ajaxError(jqXHR) {
        console.error('Error: ', jqXHR.responseText);
    }
});
const request = require('request');
var name = 'Neptune';
request.get({
  url: 'https://api.api-ninjas.com/v1/planets?name=' + name,
  headers: {
    'X-Api-Key': 'YOUR_API_KEY'
  },
}, function(error, response, body) {
  if(error) return console.error('Request failed:', error);
  else if(response.statusCode != 200) return console.error('Error:', response.statusCode, body.toString('utf8'));
  else console.log(body)
});
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import com.fasterxml.jackson.databind.ObjectMapper;

URL url = new URL("https://api.api-ninjas.com/v1/planets?name=Neptune");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept", "application/json");
InputStream responseStream = connection.getInputStream();
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(responseStream);
System.out.println(root.path("fact").asText());
let name = "Neptune".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
let url = URL(string: "https://api.api-ninjas.com/v1/planets?name="+name!)!
var request = URLRequest(url: url)
request.setValue("YOUR_API_KEY", forHTTPHeaderField: "X-Api-Key")
let task = URLSession.shared.dataTask(with: request) {(data, response, error) in
    guard let data = data else { return }
    print(String(data: data, encoding: .utf8)!)
}
task.resume()
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.