I have a problem accessing the World-check-one API. Please help me. The same request parameter, i...

...n which the name parameter is Chinese, returns 401 Unauthorized, the name can be changed to English after the normal request.
您好,我在访问World-check-one API时遇到问题。请帮我。name参数为Chinese的相同请求参数返回401 Unauthorized,正常请求后名称可以更改为英文。以下是DEMO根据您的官方API实施的测试类
postrequest.txt // A simple request to create a Case using Http Post
public static void main(String[] args) throws Exception {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
Date now = new Date();
//format for date string Mon, 27 Mar 2017 15:19:36 GMT
DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",Locale.ENGLISH);
df.setTimeZone(TimeZone.getTimeZone("GMT"));
String date = df.format(now);
String gatewayurl = "/v1/";
String gatewayhost = "rms-world-check-one-api-pilot.thomsonreuters.com";
String apikey = "xxxxx";
String apisecret = "xxx";
String groupid = "0a3687d0-6a26-186f-9a9b-af9100000a4b";
//create a JSON string
String jsonBody = "{\"secondaryFields\":[{\"typeId\":\"SFCT_1\",\"value\":\"FEMALE\"},{\"dateTimeValue\":\"1946-09-14\",\"typeId\":\"SFCT_2\"},{\"typeId\":\"SFCT_5\",\"value\":\"CHN\"}],\"entityType\":\"INDIVIDUAL\",\"groupId\":\"0a3687d0-6a26-186f-9a9b-af9100000a4b\",\"providerTypes\":[\"WATCHLIST\"],\"name\":\"杨秀珠\"}";
// create a JSON object from the JSON string
JSONObject jo = new JSONObject(jsonBody);
//System.out.println(jo.toString());
String jlen = String.valueOf(jo.toString().length());
String dataToSign = "(request-target): post " + gatewayurl + "cases/screeningRequest\n" +
"host: " + gatewayhost + "\n" +
"date: " + date + "\n" +
"content-type: " + "application/json" +"\n" +
"content-length: " + jlen + "\n" +
jo;
String hmac = generateAuthHeader(dataToSign, apisecret);
String authorisation = "Signature keyId=\"" + apikey + "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\"" + hmac + "\"";
System.out.println(jlen);
System.out.println(dataToSign);
//System.out.println(hmac);
System.out.println(authorisation);
String msg = jsonBody.toString();
HttpPost httpPost = new HttpPost("https://rms-world-check-one-api-pilot.thomsonreuters.com/v1/cases/screeningRequest");
HttpEntity entity = new StringEntity(msg);
httpPost.setEntity(entity);
httpPost.addHeader("Date", date);
httpPost.addHeader("Cache-Control", "no-cache");
httpPost.addHeader("Content-Type", "application/json" );
httpPost.addHeader("Authorization", authorisation);
// send the POST request
CloseableHttpResponse response1 = httpclient.execute(httpPost);
try {
HttpEntity entity1 = response1.getEntity();
System.out.println(response1.getStatusLine());
String json = EntityUtils.toString(response1.getEntity());
//System.out.println(entity1);
// json string returned
System.out.println(json);
ObjectMapper mapper = new ObjectMapper();
// printout in Pretty format
Object jsonObj = mapper.readValue(json, Object.class);
String indented = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonObj);
System.out.println(indented);
EntityUtils.consume(entity1);
}
finally {
response1.close();
}
} finally {
httpclient.close();
}
}
Best Answer
-
Hi @wangguoqing,
please reference below:
function generateAuthHeader(dataToSign){
var hash = CryptoJS.HmacSHA256(dataToSign,environment["api-secret"]);
return hash.toString(CryptoJS.enc.Base64);
}
function isEnvValuePopulated(envVal) {
if (_.isEmpty(pm.environment.get(envVal))) {
pm.environment.set(envVal, "--REQUIRED-VALUE-MISSING--");
return false;
} else {
return true;
}
}
isEnvValuePopulated("group-id");
var date = new Date().toGMTString();
var content = request.data;
content = content.replace("{{group-id}}", environment["group-id"]);
var contentLength = unescape(encodeURIComponent(content)).length;
var dataToSign = "(request-target): post " + environment["gateway-url"] + "cases\n" +
"host: " + environment["gateway-host"] + "\n" +
"date: " + date + "\n" +
"content-type: " + environment["content"] +"\n" +
"content-length: " + contentLength + "\n" +
content;
var hmac = generateAuthHeader(dataToSign);
var authorisation = "Signature keyId=\"" + environment["api-key"] + "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\"" + hmac + "\"";
postman.setEnvironmentVariable("authorisation",authorisation);
postman.setEnvironmentVariable("currentDate",date);
postman.setEnvironmentVariable("contentLength",contentLength);0
Answers
-
Thank you for your query.
Can you please let us know if you are enconding the request payload with UTF-8 encoding? If not, please use UTF-8 encoding for the request body. After the UTF-8 encoding, you should not get Error 401 for foreign character.
If you face the issue after UTF-8 encoding, please share the request and the response headers of the failed request along with the request body to investigate further.
Hope this helps.
0 -
Hi Prabhjyot.Mandla
Hello, I've tried UTF-8 encoding for requests, but I still can't. Can you fill in what you think is the correct code in the Java sample given above?0 -
-
Hi Prabhjyot.Mandla
Can you provide an example of World Check One API Java code that can use Chinese names as request parameters?0 -
0
-
Hi Prabhjyot.Mandla Thanks a lo. I'll try.
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
- 690 Datastream
- 1.4K DSS
- 629 Eikon COM
- 5.2K Eikon Data APIs
- 11 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 255 ETA
- 559 WebSocket API
- 39 FX Venues
- 15 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 25 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 279 Open PermID
- 45 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 715 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
- 106 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 95 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛