Not Monitored
Tag not monitored by Microsoft.
35,986 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to generate a token to connect to a third party API as per below instructions:
Below is my C# code. When I run it the reponse states unauthorised. Any ideas why? Using the same credentials I can connect via Postman.
RestClient client = new RestClient("https://ourcompany.pentanarpm.uk/cpmweb/oauth/token");
RestRequest request = new RestRequest() { Method = Method.POST };
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes("api_client:9517713b-eef2-40fc-ab3c-473c1b8129aa");
string userNamePasswordEncodedBase64 = System.Convert.ToBase64String(plainTextBytes);
//Add Headers
request.AddHeader("Accept", "application/json");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Authorization", "Basic {" + userNamePasswordEncodedBase64 + "}");
var body = new
{
grant_type = "password",
username = "ourcompany.Pentana.api",
Password = "bcbbe8c0-e2e8-4d92-9c0a-be954517742f"
};
request.AddJsonBody(body);
IRestResponse token = null;
var response = client.Execute(request);