How to lookup vehicle information based on vehicle ID number
The US Dept of Transportation provides examples of how to use their api, with multiple programming languages at:
https://vpic.nhtsa.dot.gov/api/Home/Index/LanguageExamples
https://vpic.nhtsa.dot.gov/api/
How can this information be used to bring vehicle data (ie. year, make, model, body type) into a Ninox database, by entering a vehicle identification number?
11 replies
-
Hi Dean,
This is what I use to get a translation from Google...
let googleResponse := http("POST", "https://translation.googleapis.com/language/translate/v2?key=" + googleKey + "&q=" + urlEncode(string) + "&source=de&target=en&format=text");
if googleResponse.error then
alert(text(googleResponse.error))
else
let objTranslation := googleResponse.result;
item(objTranslation.data.translations, 0).translatedText
end
You can do something similar with their examples as a guide. Once you get a valid response, you can use the
item()
function to get the information you want or make your own parsing routine. I found that if I copy the response and assign it to a variable in a formula field and then save the change the Ninox editor will helpfully format the JSON result with carriage returns and indents that will make understanding the result easier.For example, when you click on JSON here...
...you get this...
...if you assign it to a variable in a formula field you get this...
-
Sean, thank you for your help. I seem to still be missing a piece of the puzzle. If the result returned is:
{
"SearchCriteria": "VIN(s): 5UXWX7C5*BA",
"Results": [{
"Year": "2011",
"Make": "BMW",,
"Model": "X3"
}]
}
How do I get the Year, Make and Model data into Ninox fields? I have read the Ninox documentation at:
https://ninox.com/en/manual/api/http-calls
and reviewed your sample, but have not been able to retrieve the data using the item() function.
-
I've made progress. The below item() function returns "X3":
let response := {
SearchCriteria: "VIN(s): 5UXWX7C5*BA",
Results: [{
Year: "2011",
Make: "BMW",
Model: "X3"
}]
};
let v := item(response.Results, 0).Model;
alert(v)
-
Dean, when the result is returned and assigned to a variable, nhtsaResponse for example, you would use
item()
like this...YourYearField := item(nhtsaResponse.Results, 0).Year
-
You beat me to it
-
It is now working. Anyone can try it. It uses one field named 'Veh ID No.' and the below button code. It only requires the first 10 characters of the 17 character vehicle ID number. It can pull in a lot more information, but this is a good proof of concept.
let _url := "https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVinValues/" + 'Veh ID No.' + "?format=json";
let _response := http("get", _url);
let _obj := _response.result;
let _year := item(_obj.Results, 0).ModelYear;
let _make := item(_obj.Results, 0).Make;
let _model := item(_obj.Results, 0).Model;
let _veh := _year + " " + _make + " " + _model;
alert(_veh)
Thank you very much Sean!
-
How can I loop through and return the name and value of only those items that contain a value?
-
Dean, I would just copy the results to a temporary table and then you can use filters
-
Okay. Thank you Sean.
-
This was very helpful to me. Once I realized where the ".Results" portion of the item function came from it, it all fell into place. (For any future developers reading this, ".Results" is part of the JSON object returned.
@Sean, I can't seeem to figure out where the record layout screen above came from (the one in color starting with "let result :={" ). Was that section of code with data somehow generated...showing the element titles along with the parsed JSON data? -
Stephen, That screenshot is from the Ninox formula/code editor. All I did was take the unformatted JSON result and assigned it to a variable in a Formula field. When you exit the code editor after that and then go back into the editor, the JSON result will be nicely formatted for you.
Content aside
- 4 yrs agoLast active
- 11Replies
- 2124Views