Getting 401 Unauthorized World Check API

import requests
import hmac
import hashlib
import base64
import time
import json
import io
null = None
false = None
# To get the GMT time string
dataformat = ("%a, %d %b %Y %H:%M:%S GMT")
datenow = time.gmtime()
date = time.strftime(dataformat, datenow)
print(date)
api_key = "xxxxxxxxxxxxxxxxxxxx" # Enter your API key
api_secret = "xxxxxxxxxxxxxxxxxxxxxxx" # Enter your API secret
group_id = "xxxxxxxxxxxxxxxxxxxxxxx" # Enter your group Id
api_token = api_secret.encode()
path = "https://rms-world-check-one-api-pilot.thomsonreuters.com/v2/cases"
gatewayurl = "/v2/"
gatewayhost = "rms-world-check-one-api-pilot.thomsonreuters.com"
content_type = "application/json"
name1 = "putin"
entity_type = "INDIVIDUAL"
bcontent = "{\n\"secondaryFields\": [],\n \"entityType\": \"" + entity_type + "\",\n \"customFields\": [],\n \"groupId\":\"" + group_id + "\",\n \"providerTypes\": [\n \"WATCHLIST\"\n ],\n \"name\": \"" + name1 + "\"}"
content = bcontent.encode('utf-8')
length = len(content)
str_length = str(length)
datatosign = "(request-target): post " + gatewayurl + "cases/screeningRequest\n" + \
"host: " + gatewayhost + "\n" + \
"date: " + date + "\n" + \
"content-type: " + content_type + "\n" + \
"content-length: " + str_length + "\n" + \
content.decode()
print(datatosign)
byte_datatosign = datatosign.encode()
def hbase(byte_datatosign, api_token):
encrypt = hmac.new(api_token, byte_datatosign, digestmod=hashlib.sha256)
digest_maker = encrypt.digest()
base = base64.b64encode(digest_maker)
return base.decode()
hmacbase = hbase(byte_datatosign, api_token)
print(hmacbase)
authorisation = "Signature keyId=\"" + api_key + "\"" + ",algorithm=\"hmac-sha256\"" + ",headers=\"(request-target) host date content-type content-length\"" + ",signature=\"" + hmacbase + "\""
print(authorisation)
headers = {
'Authorization': authorisation,
'Date': date,
'Content-Type': content_type,
'Content-Length': str_length,
'Accept': "*/*",
'Cache-Control': "no-cache",
'Host': "rms-world-check-one-api-pilot.thomsonreuters.com",
'Accept-Encoding': "gzip, deflate",
'Connection': "keep-alive",
'cache-control': "no-cache"
}
print(headers)
try:
result = requests.request("POST", path, headers=headers, data=content)
result.raise_for_status()
print(result.status_code)
print(result.headers)
result_json = result.json()
with io.open("result_json.txt", 'w', encoding="utf-8") as outfile:
outfile.write(str(json.dumps(result_json, ensure_ascii=False, indent=4)))
print(result_json)
except requests.exceptions.HTTPError as errh:
print("Http Error:", errh)
except requests.exceptions.ConnectionError as errc:
print("Error Connecting:", errc)
except requests.exceptions.Timeout as errt:
print("Timeout Error:", errt)
except requests.exceptions.RequestException as err:
print("OOps: Something Else", err)
Best Answer
-
Hi,
I would like to highlight an observation that I made on the path that you have declared in the code i.e "https://rms-world-check-one-api-pilot.thomsonreuters.com/v2/cases" which is for the endpoint to save a case API(async screening) and I also see that in dataToSign section of the code the endpoint declared is of sync screening i.e. "cases/screeningRequest".
There is an obvious discrepancy here and I believe this might be the potential cause for the 401 that you're observing. Please clarify the endpoint that you would like to use i.e. save a case or sync screen a case and make the corrections accordingly under the path and dataToSign section of your code.
Let me know if this solves the issue.
Regards,
Mehran Khan
0
Answers
-
APIs are working fine in postman but not in python they are returning 401
0 -
I want to save the case.
0 -
Please edit the endpoint detail in your dataToSign section to just "cases" from "cases/screeningRequest".
Let me know if this works.
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
- 687 Datastream
- 1.4K DSS
- 621 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
- 254 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
- 276 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
- 669 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
- 48 中文论坛