The Cars API provides detailed information on thousands of vehicle models from over a hundred automakers.
HTTP GET
Get car data from given parameters. Returns a list of car models (and their information) that satisfy the parameters.
make
(optional) - vehicle manufacturer (e.g. audi
or toyota
).
model
(optional) - vehicle manufacturer (e.g. a4
or corolla
).
fuel_type
(optional) - type of fuel used. Possible values: gas
, diesel
, electricity
.
drive
(optional) - drive transmission. Possible values: fwd
(front-wheel drive), rwd
(rear-wheel drive), awd
(all-wheel drive), 4wd
(four-wheel drive).
cylinders
(optional) - number of cylinders in engine. Possible values: 2
, 3
4
, 5
, 6
, 8
, 10
, 12
, 16
.
transmission
(optional) - type of transmission. Possible values: manual
, automatic
.
year
(optional) - vehicle model year (e.g. 2018
).
min_city_mpg
(optional) - minimum city fuel consumption (in miles per gallon).
max_city_mpg
(optional) - maximum city fuel consumption (in miles per gallon).
min_hwy_mpg
(optional) - minimum highway fuel consumption (in miles per gallon).
max_hwy_mpg
(optional) - maximum highway fuel consumption (in miles per gallon).
min_comb_mpg
(optional) - minimum combination (city and highway) fuel consumption (in miles per gallon).
max_comb_mpg
(optional) - maximum combination (city and highway) fuel consumption (in miles per gallon).
limit
(optional) - How many results to return. Must be between 1
and 50
. Default is 5
.
X-Api-Key
(required) - API Key associated with your account.
Live Demo!
https://api.api-ninjas.com/v1/cars?limit=2&model=
[
{
"city_mpg": 18,
"class": "midsize car",
"combination_mpg": 21,
"cylinders": 4,
"displacement": 2.2,
"drive": "fwd",
"fuel_type": "gas",
"highway_mpg": 26,
"make": "toyota",
"model": "camry",
"transmission": "a",
"year": 1993
},
{
"city_mpg": 19,
"class": "midsize car",
"combination_mpg": 22,
"cylinders": 4,
"displacement": 2.2,
"drive": "fwd",
"fuel_type": "gas",
"highway_mpg": 27,
"make": "toyota",
"model": "camry",
"transmission": "m",
"year": 1993
}
]
import requests
model = 'camry'
api_url = 'https://api.api-ninjas.com/v1/cars?model={}'.format(model)
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 model = 'camry'
$.ajax({
method: 'GET',
url: 'https://api.api-ninjas.com/v1/cars?model=' + model,
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 model = 'camry'
request.get({
url: 'https://api.api-ninjas.com/v1/cars?model=' + model,
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/cars?model=camry");
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 url = URL(string: "https://api.api-ninjas.com/v1/cars?model=camry"!)!
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()