Making a GET request in R

jgozal picture jgozal · Feb 22, 2016 · Viewed 12.1k times · Source

I've been playing a little with httr and rcurl and cannot manage to translate the following curl GET request into R:

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer 31232187asdsadh23187' 'https://this.url.api.com:334/api/endpoint'

Particularly, I've been having some trouble to pass the Authorization option as I was not able to find the equivalent parameter in neither of the libraries. It might be a custom header maybe?

Answer

sckott picture sckott · Feb 22, 2016
httr::GET('https://this.url.api.com:334/api/endpoint', 
      accept_json(), 
      add_headers('Authorization' = 'Bearer 31232187asdsadh23187'))

See also https://github.com/hrbrmstr/curlconverter