Idiots guide to API in R please?

Hi all,
Pretty comfortable using RStudio but never queried an API before.
I have an API key for Realtime Vehicle Positions API, is there any R savvy forum members who could help me through a brief query template?

Hey Dean,

I did some digging about how to get the positions into R and came up with this solution.

install.packages('devtools')
install.packages('httr')
devtools::install_github("SymbolixAU/gtfsway")

library(httr)
library(gtfsway)

url = "https://api.transport.nsw.gov.au/v1/gtfs/vehiclepos/sydneytrains"
response <- httr::GET(url, add_headers(Authorization = "apikey yourkey"))

FeedMessage <- gtfs_realtime(response)
positions = gtfs_vehiclePosition(FeedMessage)

View(positions)

positions[sample(1:length(positions),1)]

Hope this helps!

Best,
Jack

3 Likes

Thanks!
Response was very helpful and I can tweak it for other APIs.

Much appreciated

2 Likes