question

Upvotes
Accepted
3 1 0 0

get data using API in python

I want to retrieve the data using python


This is the following code. Please tell me where am I doing wrong.


##create authentication request URL, message and header

authenMsg = {'CreateServiceToken_Request_1': { 'ApplicationID':appid, 'Username':username,'Password':password }}

authenURL = 'https://api.trkd.thomsonreuters.com/api/TokenManagement/TokenManagement.svc/REST/Anonymous/TokenManagement_1/CreateServiceToken_1'

headers = {'content-type': 'application/json;charset=utf-8'}

result = requests.post(authenURL, data = json.dumps(authenMsg), headers=headers)

try:

if result.status_code == 200:

print('response status %s'%(result.status_code))

token = result.json()['CreateServiceToken_Response_1']['Token']

print('Token: %s'%(token))

expire = result.json()['CreateServiceToken_Response_1']['Expiration']


else:

print('response status %s'%(result.status_code))

if result.status_code == 500: ## if username or password or appid is wrong

print('Error: %s'%(result.json()))

result.raise_for_status()

except requests.exceptions.RequestException as e:

print('Exception!!!')

print(e)

sys.exit(1)


headers_ = {

"POST": "/api/Fundamentals/Fundamentals.svc HTTP/1.1"

,"Content-Type": "application/soap+xml"

,"Host": "api.trkd.thomsonreuters.com"

,"Content-Length": "1"

,'X-Trkd-Auth-Token': token

}

url = "http://api.trkd.thomsonreuters.com/api/Fundamentals/Fundamentals.svc"

r = requests.post(url, data = json.dumps(authenMsg), headers=headers_)

print(r)




pythonrkd-apirkd
icon clock
10 |1500

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

Moving to TRKD forum

Upvote
Accepted
11.5k 16 7 10

Hello @tarun_dutta

I have checked your error message and the code. The problems are following:

  1. The application sends the HTTP Post request message to RKD Fundamental Service SOAP endpoint. You cannot send the HTTP Post request message to the SOAP API endpoint
  2. The application sends the authentication request message as a Fundamental request message to RKD Fundamental service.

I strongly suggest you check the RKD Fundamental Service information in RKD API Catalog page, then choose Fundamentals --> Get General Information. The service supports both SOAP and HTTP JSON interfaces. You can find the url endpoint, request message detail and example result from the page.

Based on RKD API page above, the URL for Fundamentals service : General Company Information HTTP JSON interface is

http://api.trkd.thomsonreuters.com/api/Fundamentals/Fundamentals.svc/REST/Fundamentals_1/GetGeneralInformation_1

The example request message in JSON format is following:

{
    "GetGeneralInformation_Request_1": {
        "companyId": "IBM.N",
        "companyIdType": "RIC",
        "ShowReferenceInformation": False
    }
}

I have tested the following example code, and it works fine in my environment.

fundamental_header= {
    'content-type': 'application/json',
     'X-Trkd-Auth-ApplicationID': appid, 
     'X-Trkd-Auth-Token': token
}
fundamental_request_message = {
    "GetGeneralInformation_Request_1": {
        "companyId": "IBM.N",
        "companyIdType": "RIC",
        "ShowReferenceInformation": False
    }
}
url = "http://api.trkd.thomsonreuters.com/api/Fundamentals/Fundamentals.svc/REST/Fundamentals_1/GetGeneralInformation_1"
result = requests.post(url, data = json.dumps(fundamental_request_message), headers=fundamental_header)
print(result.json())

fundamental.png (168.5 KiB)
fundamental-2.png (165.7 KiB)
icon clock
10 |1500

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

Hi @tarun_dutta

Please be informed that the RKD API endpoints have been changed from "api.trkd.thomsonreuters.com" to "api.rkd.refinitiv.com". you can find more detail in this https://my.refinitiv.com/content/mytr/en/pcnpage/11735.html link.

Thanks It worked How do I get the company id for some companies at one shot using api query

Upvotes
13k 32 12 18

Hi @tarun_dutta,

Your code seems to be ok. What is the issue?

Have you seen TRKD samples at Refinitiv API github?

icon clock
10 |1500

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

Upvotes
13k 32 12 18

I ran your code and was able to get a token:

response status 200
Token: E3E7AE98E64D8DE3B4E5720******C4137D
<Response [400]>
icon clock
10 |1500

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

Upvote
11.5k 16 7 10

Hello @tarun_dutta

Could you please give me more detail regarding the error you got, example error message?

Please note that the given code is just the code for authenticating for TRKD service token, the application needs to use this service token (and the application id) when request data from the other TRKD services (Quote, Estimate, Time-Series, News, Research, etc).


The application needs to set the Application ID and service Token with the request message HTTP header to identify the permission.

  • X-Trkd-Auth-ApplicationID: Application ID
  • X-Trkd-Auth-Token: service Token

For more detail, please see an example of how to request TRKD data after you get a service token from the following resources:

icon clock
10 |1500

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

Hi
The error is 400.


I have passed the appid, and token in data.



headers_ = {

"POST": "/api/Fundamentals/Fundamentals.svc HTTP/1.1"

,"Content-Type": "application/soap+xml"

,"Host": "api.trkd.thomsonreuters.com"

,"Content-Length": "1"

}


reqmsg = {'X-Trkd-Auth-ApplicationID': appid

,'X-Trkd-Auth-Token': token}

url = "http://api.trkd.thomsonreuters.com/api/Fundamentals/Fundamentals.svc"

r = requests.post(url, data = json.dumps(reqmsg), headers=headers_)

print(r)


However, I am getting


response status 200 
Token: 029F398BA861B10AC4DC90F6B2FBD55C6FADE5DB3FAC5DFBCEF5B21C2DD3A93E128DAA983DC1AF43377D94D5F6CDA6198729263B51DC33C08423465C2967BB78983654FF282F33FEC5C8764C6023C944191750086E98181DBB9C19F351D 
<Response [400]>
Click below to post an Idea Post Idea