Language Examples

C#

Get Example


string url = "https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeId/440?format=json";
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
try
{
	var tmp = client.GetAsync(url).Result;
	if (tmp.IsSuccessStatusCode)
		var result = tmp.Content.ReadAsStringAsync();
}
catch (Exception err)
{
	// error handling
}
			

Post Example


string text = "3GNDA13D76S000000;5XYKT3A12CG000000;";
string url = @"https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/";
var nameValues = new Dictionary<string, string>();
nameValues.Add("data", text);
nameValues.Add("format", "json");
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(url);
		
// using FormUrlEncodedContent
var name = new FormUrlEncodedContent(nameValues);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
System.Threading.CancellationToken token = new System.Threading.CancellationToken();
try
{
	var tmp = client.PostAsync(client.BaseAddress, name, token).Result;
	var result = tmp.Content.ReadAsStringAsync();
}
catch (Exception err)
{
	// error handling
}
		

VB.NET

Get Example


Dim url As String
url = "https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeId/440?format=json"
Dim client = New HttpClient()
client.BaseAddress = New Uri(url)
client.DefaultRequestHeaders.Accept.Add(New System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"))
Dim tmp As System.Net.Http.HttpResponseMessage
Dim result As System.Threading.Tasks.Task(Of String)
Try
	tmp = client.GetAsync(url).Result
	If (tmp.IsSuccessStatusCode) Then
		result = tmp.Content.ReadAsStringAsync()
	End If
Catch ex As Exception
	' error handling
End Try
	

Post Example


Dim uri As String
Dim SemiColonSepVins As String
Dim tmp As System.Net.Http.HttpResponseMessage
Dim result As System.Threading.Tasks.Task(Of String)
Try
	uri = "https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/"
	SemiColonSepVins = "5XYKT3A12CG000000;3D7KU28C54G000000;"
	Dim client = New HttpClient()
	client.BaseAddress = New Uri(uri)
	Dim nameValues As New Dictionary(Of String, String)
	nameValues.Add("data", SemiColonSepVins)
	nameValues.Add("format", "json")
	Dim name = New FormUrlEncodedContent(nameValues)
	client.DefaultRequestHeaders.Accept.Add(New System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"))
	Dim token = New System.Threading.CancellationToken()
	tmp = client.PostAsync(client.BaseAddress, name, token).Result
	result = tmp.Content.ReadAsStringAsync()
Catch ex As Exception
	' error handling
End Try

	

Javascript with jQuery

Get Example


$.ajax({
	url: "https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeId/440?format=json",
	type: "GET",
	dataType: "json",
	success: function(result)
	{
		console.log(result);
	},
	error: function(xhr, ajaxOptions, thrownError)
	{
		console.log(xhr.status);
		console.log(thrownError);
	}
});
			

Post Example


$.ajax({
	url: "https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/",
	type: "POST",
	data: { format: "json", data: "3GNDA13D76S000000;5XYKT3A12CG000000;"},
	dataType: "json",
	success: function(result)
	{
		console.log(result);
	},
	error: function(xhr, ajaxOptions, thrownError)
	{
		console.log(xhr.status);
		console.log(thrownError);
	}
});
		

PHP

Get Example


<?php
	$opts = array('http' =>
		array(
			'method' => 'GET',
			'content' => $postdata
		)
	);
	$apiURL = "https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeId/440?format=json";
	$context = stream_context_create($opts);
	$fp = fopen($apiURL, 'rb', false, $context);
	if(!$fp)
	{
		echo "in first if";
	}
	$response = @stream_get_contents($fp);
	if($response == false)
	{
		echo "in second if";
	}
	echo $response;
?>
		

Post Example


<?php
	$postdata = http_build_query(
		array(
				'format' => 'json',
				'data' => '3GNDA13D76S000000;5XYKT3A12CG000000'
			)
	);
	$opts = array('http' =>
		array(
			'method' => 'POST',
			'content' => $postdata
		)
	);
	$apiURL = "https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/";
	$context = stream_context_create($opts);
	$fp = fopen($apiURL, 'rb', false, $context);
	if(!$fp)
	{
		echo "in first if";
	}
	$response = @stream_get_contents($fp);
	if($response == false)
	{
		echo "in second if";
	}
	echo $response;
?>		
				

Python

Get Example


import requests,json;
url = 'https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeId/440?format=json';
r = requests.get(url);
print(r.text);		
			

Post Example


import requests,json;
url = 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/';
post_fields = {'format': 'json', 'data':'3GNDA13D76S000000;5XYKT3A12CG000000'};
r = requests.post(url, data=post_fields);
print(r.text);		
			

Ruby

Get Example


require 'certified'
require 'net/http'
require 'json'
url = 'https://vpic.nhtsa.dot.gov/api/vehicles/GetModelsForMakeId/440?format=json'
uri = URI(url)
response = Net::HTTP.get(uri)
puts response		
				

Post Example


require 'certified'
require 'net/http'
require 'json'
url = 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/'
uri = URI(url)
response = Net::HTTP.post_form(uri, {"format"=>"json", "data"=>"3GNDA13D76S000000;5XYKT3A12CG000000"})
puts response.body