Hi! My first post here.
Im trying to paste multiple vin numbers into the nthsa API. Im later using this code inside of a shiny app.
My working solution looks like this:
library(jsonlite)
library(httr)
vins <- c('4JGCB5HE1CA138466','4JGCB5HE1CA138466','4JGCB5HE1CA138466','4JGCB5HE1CA138466','4JGCB5HE1CA138466','4JGCB5HE1CA138466','4JGCB5HE1CA138466','4JGCB5HE1CA138466','4JGCB5HE1CA138466','4JGCB5HE1CA138466','4JGCB5HE1CA138466',)
for (i in vins){
json <- fromJSON(paste0('https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVinValues/',i,'?format=json'))
print(json)
}
This solution is very slow. I tried pbapply, same thing because it pastes one vin at a time.
There is a batch paste option that i just cant figure out. Can someone please assist.
Here is my code so far:
headers = c(
`Content-Type` = 'application/json'
)
data = '[{"data":"4JGCB5HE1CA138466;4JGCB5HE1CA138466;4JGCB5HE1CA138466;4JGCB5HE1CA138466"}]'
httr::POST(url = 'https://vpic.nhtsa.dot.gov/api/vehicles/DecodeVINValuesBatch/', httr::add_headers(.headers=headers), body = data)
print(r$status_code)
I am getting status code 200 but server code 500 with no data.
The vin numbers string has to be in the following format: vin;vin;vin;vin;
here is the link: https://vpic.nhtsa.dot.gov/api/ (the last one)
her, they also provide instructions for other languages: https://vpic.nhtsa.dot.gov/api/Home/Index/LanguageExamples
Thanks in advance.