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.
Best Answer
-
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);0
Answers
-
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.
0 -
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!
0 -
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);
0 -
Hi, it is not working. I included "%40tr.com" becaus it is what I saw in the API Playgroud.
0 -
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!
0 -
Use this -
var payloadStr = string.Format("grant_type=password&username={0}&scope=trapi&client_id={2}&password={1}&takeExclusiveSignOnControl=true", user, password, appKey);
1
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛