Problems getting a Post call put together for API

I'm new to API's and having problems getting a Post call put together so that i can obtain my bearer token.
Any help on how to use httr so that I can get a post call together would be very helpful.
Below is from the developer portal of the experian sandbox which I am currently using.

"The call to get the Oauth2 token is a POST request with a Content-Type which needs to be specified as JSON;
the response will also be in JSON format:"

Request example:

curl -X POST
-d '{"username": "youremail@email.com", "password": "YOURPASSWORD"}'
-H "Client_id: 3QC11Sm45ti8wXXxx9A5hma5XIlXXXXX"
-H "Client_secret: ipu3WXXxTExxZDXW"
-H "Cache-Control: no-cache"
-H "Content-Type: application/json"
"https://sandbox.APIurl.com/oauth2/v1/token"

I think your httr:POST will look something like this;

post_req <- httr::POST(
  "https://sandbox.APIurl.com/oauth2/v1/token",
  add_headers(
    "Content-Type" = "application/json", 
    "Cache-Control"="no-cache",
    "Client_secret"="ipu3WXXxTExxZDXW",
    "Client_id"="3QC11Sm45ti8wXXxx9A5hma5XIlXXXXX"),
  body = '{"username": "youremail@email.com", "password": "YOURPASSWORD"}',
  verbose()
)

Have you seen the vignettes?
https://cran.r-project.org/web/packages/httr/vignettes/quickstart.html
https://cran.r-project.org/web/packages/httr/vignettes/api-packages.html
https://cran.r-project.org/web/packages/httr/vignettes/secrets.html

2 Likes

Curtis, thank you very much. I'll read up on the links you included tonight.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.