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 }}
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)
Hello @tarun_dutta
I have checked your error message and the code. The problems are following:
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())
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
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.
For more detail, please see an example of how to request TRKD data after you get a service token from the following resources:
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]>