question

Upvotes
Accepted
0 0 1 3

Curl request with PHP - Where can I find parameters ?

I'm trying to make a curl request with PHP to the endpoint https://api.refinitiv.com/auth/oauth2/v1/token in order to get an access_token, which I can then use to access the other endpoints that Refinitiv provides. However, I'm encountering some difficulties. From what I understand, the following fields are mandatory:

  • grant_type ("password")
  • username (my email address)
  • password (my password)

On the other hand, I have no idea where I can find the following information:

  • scope
  • client_id
  • client_secret

Having combed through the rather thin associated documentation, the client_id and client_secret would be associated with my application created via the AppKey Generator, but if the field names matched what I can see there, that would be too easy. So, do you know where I can find the "scope" parameter, and what do "client_id" and "client_secret" correspond to in the AppKey Generator?

Thank you very much for your help!

phprequest-tokenapi-key
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.

Upvote
Accepted
79.2k 251 52 74

@edouard.chene

The PHP code for Authentication V1 should look like this:

<?php
$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://api.refinitiv.com/auth/oauth2/v1/token',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => 'username=<username>&password=<password>&grant_type=password&scope=trapi&takeExclusiveSignOnControl=true&client_id=<client id>',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/x-www-form-urlencoded'
  ),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;

This code is generated by Postman. You can download the RDP Postman collection from here and refer to this article: Generate code for a REST API call using Postman in just a few clicks regarding how to generate code from Postman

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.

Upvote
22.1k 59 14 21

Yes, you can use CURL to get an access token. Use following command:

curl -v -X POST -H "Accept: application/json" -d "username=<<__MACHINE_ID__>>&password=<<__PASSWORD__>>&client_id=<<__APP_KEY__>>&grant_type=password&scope=trapi&takeExclusiveSignOnControl=true" https://api.refinitiv.com/auth/oauth2/v1/token

replace the parameters with your username/machineID, password and APP Key.

This quickstart guide shows how to create your app key.

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.

Thank you both for your answers, you have solved my problem! It's puzzling not to simply have a public key and a private key like any other API, and you can't say that the documentation is very clear on that... One must guess that the client_id is the API key haha.

Yes, the public/private key pair support is enabled in the v2 authentication - which will also allow the JWT keypair for authorization.

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.