RDP News Wealth API
Hi running the below code (with my app key) and it does not seem to working is there anything obvious I am doing wrong?
import requests
import json
import pandas as pd
# Set up authentication headers
headers = {
'Authorization': 'APPKEY',
'Content-Type': 'application/json'
}
# Define search criteria
search_term = 'Rolls-Royce'
start_date = '2022-04-24T00:00:00Z'
end_date = '2022-05-01T23:59:59Z'
# Define endpoint and query parameters
endpoint = 'https://api.refinitiv.com/data/news/v1/articles'
params = {
'query': search_term,
'startTime': start_date,
'endTime': end_date,
'language': 'en',
'count': 100,
'includeSentiment': True
}
# Make request and get response
response = requests.get(endpoint, headers=headers, params=params)
# Convert response to JSON
data = json.loads(response.text)
# Extract sentiment information and aggregate by day
df = pd.DataFrame(data['data'])
df['publishedDate'] = pd.to_datetime(df['publishedDate'], format='%Y-%m-%dT%H:%M:%SZ')
df['sentiment'] = df['sentiment'].apply(lambda x: x['score'])
df = df.groupby(pd.Grouper(key='publishedDate', freq='D'))['sentiment'].mean().reset_index()
# Print result
print(df)
Best Answer
-
Hello @danny.mullins1
Thank you for reaching out to us. Please see my answer below:
### RDP Authentication ###
Firstly, the application cannot access the RDP service with just the App Key credential (like the Eikon Data API does).
The RDP entitlement check is based on OAuth 2.0 specification. The first step of an application workflow is to get a token from RDP Auth Service, which will allow access to the protected resource, i.e. data REST API.
The API requires the username, password, and Client ID (aka App Key) access credential information:
Once the authentication success, the function gets the RDP Auth service response message and keeps the following RDP token information in the variables.
- access_token
- refresh_token
- expires_in
Next, after the application received the Access Token (and authorization token) from RDP Auth Service, all subsequent REST API calls will use this token to get the data via the Authorization HTTP request message header as shown below to get the data.
- Header:
- Authorization =
Bearer <RDP Access Token>
- Authorization =
Please notice the space between the
Bearer
andRDP Access Token
values.So, the code should be:
rdp_username = "RDP_USER"
rdp_password = "RDP_PASSWORD"
rdp_appkey = "RDP_APPKEY"
scope = 'trapi'
access_token = None
refresh_token = None
expires_in = 0
# Authentication
auth_url = 'https://api.refinitiv.com/auth/oauth2/v1/token'
payload = f'username={rdp_username}&password={rdp_password}&grant_type=password&scope={scope}&takeExclusiveSignOnControl=true&client_id={rdp_appkey}'
# Send HTTP Request
try:
response = requests.post(auth_url,
headers = {'Content-Type':'application/x-www-form-urlencoded'},
data = payload,
auth = (rdp_appkey, '')
)
except requests.exceptions.RequestException as exp:
print(f'Caught exception: {exp}')
if response.status_code == 200: # HTTP Status 'OK'
print('Authentication success')
access_token = response.json()['access_token']
refresh_token = response.json()['refresh_token']
expires_in = int(response.json()['expires_in'])
if response.status_code != 200:
print(f'RDP authentication failure: {response.status_code} {response.reason}')
print(f'Text: {response.text}')
sys.exit(1)
# Set up authentication headers
headers = {
'Authorization': f'Bearer {access_token}',
'Content-Type': 'application/json'
}Please find more detail on the RDP Tutorial Authorization - All about tokens page.
### RDP APIs /data/news/v1/articles Service ###
I checked the RDP API Document https://apidocs.refinitiv.com/Apps/ApiDocs page, but I cannot find /data/news/v1/articles service. The code always returns 404 page not found
Can you please confirm which service you want to use?
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
- 615 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
- 556 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
- 652 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
- 228 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 中文论坛