401 response only for POST requests

Hi,
We created a class in C# to place both GET and POST requests, but only GET requests are working.
For POST, we get a 401. So we are assuming that it's something to do with Authorization header.
I tried doing the same as the pre request script in Postman but in C# but I still can't manage to get an autorized post response.
Can someone help me with that?
FYI, both GET and POST requests using Postman are working fine (returning 200).
Here is my request and response:
Request completed.
Request: {"resource":"cases/screeningRequest","parameters":[{"name":"","value":{"groupId":"5jb7whk6ycsr1fncy3iv7a0sg","entityType":"INDIVIDUAL","providerTypes":["WATCHLIST"],"name":"Test Guy","nameTransposition":false,"secondaryFields":[{"typeId":"SFCT_1","value":"FEMALE","dateTimeValue":null},{"typeId":"SFCT_2","value":null,"dateTimeValue":{"timelinePrecision":"ON","pointInTimePrecision":"DAY","utcDateTime":895557600,"timeZone":null}},{"typeId":"SFCT_3","value":"ARG","dateTimeValue":null},{"typeId":"SFCT_4","value":"ARG","dateTimeValue":null},{"typeId":"SFCT_5","value":"ARG","dateTimeValue":null}]},"type":"RequestBody"},{"name":"Authorization","value":"Signature keyId=\"86740220-fcf5-4791-9ea4-9da2d2560890\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\"gTQfAInpk6l1MmecBcXdlbf+sashrZ1pNbTsl3YreqI=\"","type":"HttpHeader"},{"name":"Date","value":"Thu, 03 Jun 2021 18:40:45 GMT","type":"HttpHeader"},{"name":"Cache-Control","value":"no-cache","type":"HttpHeader"},{"name":"Content-Length","value":"529","type":"HttpHeader"}],"method":"POST","uri":"https://api-worldcheck.refinitiv.com/v2/cases/screeningRequest"}
Response: {"statusCode":401,"content":"","headers":[{"Name":"Date","Value":"Thu, 03 Jun 2021 18:41:04 GMT","Type":3,"DataFormat":2,"ContentType":null},{"Name":"Transfer-Encoding","Value":"chunked","Type":3,"DataFormat":2,"ContentType":null},{"Name":"Connection","Value":"keep-alive","Type":3,"DataFormat":2,"ContentType":null},{"Name":"Strict-Transport-Security","Value":"max-age=15552000, includeSubdomains","Type":3,"DataFormat":2,"ContentType":null},{"Name":"Authorization","Value":"WWW-Authenticate: Signature realm=\"World-Check One API\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\"","Type":3,"DataFormat":2,"ContentType":null}],"responseUri":"https://api-worldcheck.refinitiv.com/v2/cases/screeningRequest","errorMessage":null}
Here is the req body:
{
"groupId": "5jb7whk6ycsr1fncy3iv7a0sg",
"entityType": "INDIVIDUAL",
"providerTypes": [
"WATCHLIST"
],
"name": "Test Guy",
"nameTransposition": false,
"secondaryFields": [
{
"typeId": "SFCT_1",
"value": "FEMALE",
"dateTimeValue": null
},
{
"typeId": "SFCT_2",
"value": null,
"dateTimeValue": {
"timelinePrecision": "ON",
"pointInTimePrecision": "DAY",
"utcDateTime": 895557600,
"timeZone": null
}
},
{
"typeId": "SFCT_3",
"value": "ARG",
"dateTimeValue": null
},
{
"typeId": "SFCT_4",
"value": "ARG",
"dateTimeValue": null
},
{
"typeId": "SFCT_5",
"value": "ARG",
"dateTimeValue": null
}
]
}
Here is my code:
public async Task<IndividualScreeningRes> IndividualSyncScreening(IndividualScreeningReq body)
{
try
{
var resource = "cases/screeningRequest";
var request = PostBaseRequest(resource, body);
var response = await _restClient.ExecuteAsync(request);
LogRequest(request, response);
return result;
}
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
private IRestRequest PostBaseRequest(string resource, Object body)
{
var content = JsonConvert.SerializeObject(body);
var contentLength = HttpUtility.UrlDecode(HttpUtility.UrlEncode(content), System.Text.Encoding.Default);
var date = DateTime.UtcNow.ToString("ddd, dd MMM yyyy HH:mm:ss G\\MT", CultureInfo.InvariantCulture);
var authorization = PostAuthorizationHeader(resource, date, content, contentLength.Length);
var request = new RestRequest(resource, Method.POST)
.UseNewtonsoftJson()
.AddJsonBody(body)
.AddHeader("Authorization", authorization)
.AddHeader("Date", date)
.AddHeader("Cache-Control", "no-cache")
.AddHeader("Content-Length", contentLength.Length.ToString());
return request;
}
private string PostAuthorizationHeader(string resource, string date, string content, int contentLength)
{
var dataToSign = "(request-target): post " + _gatewayVersion + resource + "\n" +
"host: " + _gatewayHost + "\n" +
"date: " + date + "\n" +
"content-type: application/json" + "\n" +
"content-length: " + contentLength + "\n" +
content;
var hmac = GenerateAuthHeader(dataToSign);
var authorizationHeaderValue = "Signature keyId=\"" + _apiKey + "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\"" + hmac + "\"";
return authorizationHeaderValue;
}
Best Answer
-
@togetherdevs
Thanks for letting us know that API calls are working fine via POSTMAN. However, for C#, we request you kindly download the the C# API example through below link, this should help you avoid a 401 Unauthorized request return status.
https://developers.refinitiv.com/en/api-catalog/customer-and-third-party-screening/world-check-one-api/downloads0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 37 Alpha
- 167 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 705 Datastream
- 1.5K DSS
- 633 Eikon COM
- 5.2K Eikon Data APIs
- 14 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 6 Trading API
- 3K Elektron
- 1.5K EMA
- 259 ETA
- 569 WebSocket API
- 40 FX Venues
- 16 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
- 4 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 284 Open PermID
- 47 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 24 RDMS
- 2.2K Refinitiv Data Platform
- 879 Refinitiv Data Platform Libraries
- 5 LSEG Due Diligence
- 1 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
- 123 Open DACS
- 1.1K RFA
- 108 UPA
- 196 TREP Infrastructure
- 232 TRKD
- 919 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 103 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛