0

I have to post some JSON to a restful endpoint and decided to do this in R. I am aware of the httr library. However, I am not sure how to add an access token for Azure active directory. This is some code:

library(httr)

access_token <- "SomeSecretStuffeyJ0eXAiOiJKV"

json <- '{"test_data":"hello_world"}'

uri <- "https://somewhere.net/bla"

result <- POST(
         uri
         , content_type_json()
         , body = json
    )

I am not sure if I can do this using httr? Could someone please help out with code and/or suggest alternative library? Thanks!

cs0815
  • 16,751
  • 45
  • 136
  • 299
  • I saw the OAuth stuff but I use AAD. So can I use what you suggested. I used add_headers(Authorization = access_token) - now get 500 error instead of 401, which makes me think that I am past the authentication hurdle ... – cs0815 Dec 10 '19 at 17:37
  • I removed my prior comment, because I think I missed some of the subtleties of OAuth, does [this post](https://stackoverflow.com/questions/44959476/using-oauth2-0-tokens-with-rs-httr-package) help? – Mako212 Dec 10 '19 at 17:39
  • Note that post is specific to OAuth 2.0 – Mako212 Dec 10 '19 at 17:40
  • Can you point to come official documentation for the API endpoints you are trying to use? Not all endpoints do things the exact same way. – MrFlick Dec 10 '19 at 17:48
  • @MrFlick no sorry is an internal/secret-ish API. Btw, hoe do you become a "RStudio certified tidyverse trainer"? – cs0815 Dec 10 '19 at 18:02
  • The RStudio certification is described here: https://education.rstudio.com/trainers/. If it’s an internal API you’ll need clarification from the developers on what headers they expected. We can’t really help further without a reducible example. – MrFlick Dec 10 '19 at 18:16

0 Answers0