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 }}
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)
Best Answer
-
Hello @tarun_dutta
I have checked your error message and the code. The problems are following:
- 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
- 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())0
Answers
-
Moving to TRKD forum
0 -
Hi @tarun_dutta,
Your code seems to be ok. What is the issue?
Have you seen TRKD samples at Refinitiv API github?
0 -
I ran your code and was able to get a token:
response status 200
Token: E3E7AE98E64D8DE3B4E5720******C4137D
<Response [400]>0 -
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:
0 -
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]>0 -
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.
0 -
Thanks It worked How do I get the company id for some companies at one shot using api query
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 616 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 252 ETA
- 557 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 653 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 229 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛