0

I am trying to get data from Eikon Elektron cloud platform.

I ran following codes from https://github.com/Refinitiv/websocket-api/blob/master/Applications/Examples/R/market_price_authentication.R:

library(curl)
> content = paste("grant_type=", "password","&username=", user, "&password=", password, sep="") 
> h <- new_handle(copypostfields = content) 
> h 
<curl handle> (empty) 
> handle_setheaders(h, 
+ "Content-Type" = "application/x-www-form-urlencoded" 
+ ) 
> handle_setopt(h, ssl_verifypeer = FALSE, ssl_verifyhost = FALSE) 
> auth_url = paste("https://", auth_hostname, sep="")# ":", auth_port, "/getToken", sep="") 
> auth_url 
[1] "https://api.refinitiv.com/auth/oauth2/v1/token" 
> req <- curl_fetch_memory(auth_url, **handle = h**) 
> req 
$url 
[1] "https://api.refinitiv.com/auth/oauth2/v1/token" 

$status_code 
[1] 400 

$type 
[1] "application/json" 

**> h 
<curl handle> (https://api.refinitiv.com/auth/oauth2/v1/token)**

> res_headers = parse_headers(req$headers) 
> auth_json_string = rawToChar(req$content) 
> auth_json = fromJSON(auth_json_string) 
> cat(toJSON(auth_json, pretty=TRUE, auto_unbox=TRUE)) 
{ 
"error": "invalid_request" 
}

As you can see, I got invalid request error. I think the problem lies in curl_fetch_memory and that the handle=h is using same input as auth_url, however it should use something similiar to the input of content. What can I change in my code to make it work?

John Mayer
  • 103
  • 7
  • Why don't you use this line of code `paste("https://", auth_hostname, ":", auth_port, "/getToken", sep="")` in that document? – ekoam Oct 29 '20 at 09:03
  • @ekoam If you have access to Eikon Api Playground, it is said that "Provide user and password to get a token and a refresh token. https://api.refinitiv.com/auth/oauth2/v1/token" . under body:grant_type=password&username=youruser%40tr.com&scope=trapi&client_id=000aaaa1111bbb555&password=yourpassword. and under Curl: curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Accept: application/json" -H "Authorization: '"$STS_TOKEN"'" -d '' "https://api.refinitiv.com/auth/oauth2/v1/token" . So, 443 gettoken should be neglected. Additionally in Python everything works with this link. – John Mayer Oct 29 '20 at 09:26
  • Then, shouldn't you also include `scope` and `client_id` in your request body? Now I only see three parameters in `content`: grant_type, username and password. – ekoam Oct 29 '20 at 09:38
  • @ekoam Yes, I included also `content = paste("grant_type=", "password","&username=", user,"&scope=","trapi","&app_id=",app_id, "&password=", password,sep="")` and also with this `%40tr.com` in username. I believe that `handler` should be equal to body, however it simply shows auth_url. Do not know how to change it and why it happened, – John Mayer Oct 29 '20 at 10:03

1 Answers1

0

I found solution how to access the URL. In github was wrongly written that app_id in R file should equal to the code from the App Key generator in Reuters. However, app_id and client_id are different things and you should add client_id=value from App Key generator (not app_id).+ also do not forget to include trapi and etc.. to your content.

Epo Luusk
  • 37
  • 5