What format should be used to request the API without an error to screen Chinese name?

These are some information you may like to know:
Error message returned: org.springframework.web.client.HttpClientErrorException: 401
request url: https://rms-world-check-one-api-pilot.thomsonreuters.com/v1/cases/screeningRequest
httpEntity: <{"customFields":[],"entityType":"INDIVIDUAL","groupId":"0a3687d0-693a-1414-9a6d-52c700001613","name":"张三","providerTypes":["WATCHLIST"],"secondaryFields":[{"typeId":"SFCT_1","value":"MALE"},{"dateTimeValue":{"pointInTimePrecision":"DAY","timelinePrecision":"ON","utcDateTime":-485600400000},"typeId":"SFCT_2"},{"typeId":"SFCT_5","value":"HKG"}]},{Date=[5 Dec 2019 03:17:12 GMT], Authorization=[Signature keyId="4eeea3fb-d10a-4521-b083-229ed9dce00b",algorithm="hmac-sha256",headers="(request-target) host date content-type content-length",signature="Ngt2S9g3oWJ/v4vkHKCSohlzg9q1tExTkBsgf9sghHo="], Content-Length=[349], Content-Type=[application/json]}>
Response : HTTP Status Code 401
Best Answer
-
RestTemplate to POST with UTF-8 encoding
0
Answers
-
This question has been answered before in this portal.
Please have a look at the link below. This will help you understand how to screen chinese characters successfully.
0 -
Tried and it is still not working.
0 -
Request you to share the code snippets with comments so that I can see how are you sending the screening request with special characters.
0 -
@Override public WdProcessParamsDto apply(WordCheckContextDto wordCheckContextDto,
WordCheckInputParamsDto wordCheckInputParamsDto) {
WdCaseAPIReqDto caseAPIReqDto = buildRequestCaseParams(wordCheckContextDto, wordCheckInputParamsDto);
//The content body
String requestJSONParams = JSON.toJSONString(caseAPIReqDto);
int length = EscapeUtils.unescape(URLEncoder.encode(requestJSONParams)).length();
//get timestamp
String currentDateOfGmtValue = new Date().toGMTString();
String dataToSign = "(request-target): post " + configurationProperties.getGatewayUrl() + "cases/screeningRequest\n" + "host: "
+ configurationProperties.getGatewayHost() + "\n" + "date: " + currentDateOfGmtValue + "\n"
+ "content-type: application/json\n" + "content-length: " + length + "\n" + requestJSONParams;
//See below
String hmac = SecretUtils.generateSha256(configurationProperties.getSecret(), dataToSign);
String authorisation = "Signature keyId=\"" + configurationProperties.getApiKey()
+ "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\""
+ hmac + "\"";
WdProcessParamsDto paramsDto = new WdProcessParamsDto();
paramsDto.setCallURL(MessageFormat.format(APIURL, configurationProperties.getProtocol(),
configurationProperties.getGatewayHost(), configurationProperties.getGatewayUrl()));
paramsDto.setHeadAuthorization(authorisation);
paramsDto.setHeadDate(currentDateOfGmtValue);
paramsDto.setExtParams(() -> {
Map<String, Object> map = new HashMap<>(2);
map.put("Content-Length", length);
map.put("Content-Data", requestJSONParams);
return map;
});
return paramsDto;
}
//SecretUtils.generateSha256
public static String generateSha256(String secret, String message) {
String hash = "";
try {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(), "HmacSHA256");
sha256_HMAC.init(secret_key);
hash = Base64.encodeBase64String(sha256_HMAC.doFinal(message.getBytes()));
} catch (Exception e) {
System.out.println("Error");
}
return hash;
}
0 -
I see that you are using the below code to calculate the length:
int length = EscapeUtils.unescape(URLEncoder.encode(requestJSONParams)).length();
You can use the below code instead of the above:
int length = EscapeUtils.unescape(URLEncoder.encode(requestJSONParams,"UTF-8")).length();
Also, I see that you are not passing the UTF-8 enccoded JSON payload in the API request but the content of the variable requestJSONParams. Please UTF-8 encode the payload before sending it over. Please check point 5 in my first reply.
map.put("Content-Data", requestJSONParams);
0 -
Tried and same error.
Also, our project's encoding is utf-8
0 -
Edited and tried the following also not resolving the issue
map.put("Content-Data", URLEncoder.encode(requestJSONParams,"UTF-8"));
and
int length = EscapeUtils.unescape(URLEncoder.encode(requestJSONParams,"UTF-8")).length();
0 -
Instead of the below code:
URLEncoder.encode(requestJSONParams,"UTF-8"));
Can you try the below:
HttpEntity entity= new StringEntity(requestJSONParams,Charsets.UTF-8);Request you to provide me the complete request headers and response headers so that I can trouble shoot.
Kindly compare the Base64 encoded HMAC signature and content lenght generated by your code to that of the one generated by Postman to know if your signature is correct. You can do this by executing your code first, then pick up the date header value from your code and paste in the pre request script of Postman to generate the HMAC (obviously the request will fail as the date header value is obsolete but you should get the same HMAC signature). Compare both to know if they match.
0 -
It is still not working.
0 -
Let us get into a phone call to resolve this.
Please provide me a good time (with time zone) so that I can send you a webex invite.
0 -
Hi Irfan, finally we managed to resolve the matter. Thanks again for your support.
0 -
@terrence.lim Can you please help us with the solution so that it helps our other community members who have the same issue?
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.5K 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
- 560 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
- 281 Open PermID
- 46 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 2K Refinitiv Data Platform
- 724 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 中文论坛