question

Upvotes
Accepted
19 13 14 14

Cannot get access token 400

Hi, I am trying to get an access token using a c# program with password grant. My code is based on what I have found in the API Playgroud, and looks like this:

// Determine endpoint
var client = new RestClient("https://api.refinitiv.com/auth/oauth2/v1/token");
client.Timeout = -1; 

// Get credential
string user = ConfigurationManager.AppSettings.Get("RefinitivUser");
string password = ConfigurationManager.AppSettings.Get("RefinitivPassword");
string appKey = ConfigurationManager.AppSettings.Get("RefinitivAppKey");

// Set up the request
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Accept", "application/json");
request.AddParameter("application/x-www-form-urlencoded", $"grant_type=password&username={user}%40tr.com&scope=trapi&client_id={appKey}&password={password}", ParameterType.RequestBody);

response = client.Execute(request);

However, when I run the previous code I get the following response.Content:

"{\"error\":\"access_denied\" ,\"error_description\":\"Invalid username or password.\" } "

This seems strange to me, because I am sure that my credentials are correct (I use them almost everyday when I run the reuters desktop application)

Please, could you help me to identify what I am doing wrong?

Thanks in advance.

rdp-apirefinitiv-data-platformc#tokencredentials
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
22.1k 59 14 21

It works fine for me - I am able to successfully get the access token. Note that I have to do explicit string format because I am not targeting C# version 6.

Working Code:

using RestSharp;

// Determine endpoint
var client = new RestClient("https://api.refinitiv.com/auth/oauth2/v1/token");
client.Timeout = -1; 
     
// Get credential
string user = "RDP_USERNAME";
string password = "RDP_PASSWORD";
string appKey = "RDP_APPKEY";

var payloadStr = string.Format("grant_type=password&username={0}&scope=trapi&client_id={2}&password={1}", user, password, appKey);
Console.WriteLine(payloadStr);
     
// Set up the request
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Accept", "application/json");
request.AddParameter("application/x-www-form-urlencoded", payloadStr, ParameterType.RequestBody);
     
var response = client.Execute(request);
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
22.1k 59 14 21

Hi @YERAY SOSA ALONSO ,

The error is exactly what it shows in the message - you don't have the right credentials for the RDP. Note that RDP is a different product from desktop applications like Eikon and requires its own credentials.

You can try the ones you use in the API playground, although it is recommended that machine ID be used for API requests. If you had signed up for RDP, then there would be a welcome letter from Refinitiv which contains your machine ID. Machine ID is in the format GE-xxx-xxxxxx. If not, please talk to your Refinitiv Account manager to get a trial ID.

Once you do get the credentials, please start from this quickstart guide.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
19 13 14 14

Hi @Gurpreet ,

In my case I use the same credentials for Eikon and the API Playground. Moreover, I have used the refinitiv data platform library for .Net inserting the same credentials and I retrieved data. Also, I have tried the quickstart guide in python with the same credetials and it worked properly, since I was able to dowload the time series.

So, given that siuation, do you know what could be happening?

Thanks!

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
22.1k 59 14 21

Ok, I think the issue is in the form data. Try this instead -

request.AddParameter("application/x-www-form-urlencoded", $"grant_type=password&username={user}&scope=trapi&client_id={appKey}&password={password}", ParameterType.RequestBody);
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
19 13 14 14

Hi, it is not working. I included "%40tr.com" becaus it is what I saw in the API Playgroud.

apiply.png



apiply.png (47.1 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
19 13 14 14

Thank you @Gurpreet! Surprisingly, when I copied and pasted your code it worked and I got a token.

However, I have another problem. As the first time I got a token I didn't store it, I lost it. Now, I am trying to get another one, but I am getting the error: "Session quota is reached". I guess this has something to do with the refresh token, but I don't have it. Is there a way to solve that?

I have done some research and I have found that this statement must be added to get new tokens every time that I want, but it isn't working because I am getting the same error.

request.AddHeader("takeExclusiveSignOnControl", "true");

Thanks!

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Use this -

var payloadStr = string.Format("grant_type=password&username={0}&scope=trapi&client_id={2}&password={1}&takeExclusiveSignOnControl=true", user, password, appKey);


Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.