I'm trying to connect to an API using R. I have instructions from the website that I am trying to connect to on some basics of how to connect, but not about R.
The workflow as I understand it is:
- Go to the menu of this website when I'm in it and tell it to generate an Oauth client (like a 'user' for my api calls
- Take that client's identifier and 'secret' that i've just made and plug it into a post command which will get a token
- Once I have token, do all the 'normal' api stuff like get/put/etc..
I've seen articles like this: Dealing with R and rest apis and this: deal with Oauth in R
But neither of them specifically address the post command, like it mentions you need to do in this stack overflow answer.
Lastly, I do have a colleague who connects to this same system with a different program. I believe he uses Postman to set up his api's? Not sure.
Anyhow, he shared his code with me that he uses for the post, but I need to somehow translate this:
public static OAuthToken GetToken()
{
var client = new RestClient(https://yourURL.websiteOfProgram.com);
var request = new RestRequest("/company-platform-web/api/oauth/token", Method.Post);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Accept", "application/json");
request.AddParameter("grant_type", "client_credentials");
request.AddParameter("client_id", Secrets.ClientId);
request.AddParameter("client_secret", Secrets.ClientSecret);
RestResponse response = client.Execute(request);
OAuthToken token = JsonSerializer.Deserialize<OAuthToken>(response.Content);
return token;
}
To R, and I would love your help!
Lastly, it does seem like this user was doing something similar, but a- it doesn't seem like they were ever successful, and b- I'm thrown off by his wording. I have a client id and client secret, I'm assuming that's the same terms as his "Api key" and secret? Also not sure whats up with the converting to Base64