C# code post create-a-case returns 401 unauthorized

Hi,
I use the sample c# code, adding the api key and api secret. Call the get groups to get group id. Then call post cases to create a case with group id from previous call. This returns 401 unauthorized.
I use the same request body in postman and it works.
I notice some differences between postman and c# code. Postman has longer content length(171) than c# code generated(138) request. I don't know why.
Here is the request data from c# code
dataToSign = "(request-target): post/v2/cases\nhost: api-worldcheck.refinitiv.com\ndate: Fri, 09 Jul 2021 22:38:46 GMT\ncontent-type: application/json\ncontent-length: 138\n{\"entityType\":\"ORGANISATION\",\"groupId\":\"xxxxxxxxxxxxxxxxxxxxxxxxx\",\"provideTypes\":[\"WATCHLIST\"],\"name\":\"Lajnat ul Masa Eidatul Afghaniab\"}"
authorisation = "Signature keyId=\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date content-type content-length\",signature=\"vf7X29JltDSWMW938DwfnC6qW7A8XKrjCGHdDkczW9Y=\""
Please assist.
Thank you,
Cady
Best Answer
-
Thanks to Prabhjyot's help, I was able to find out the typo in the request body. I had provideType. It should be providerType.
0
Answers
-
@cadyh ,
Can you please share the request payload as it is being passed using the code and postman to compare the values?
0 -
The request using the code is in the question.
Here is the request using Postman
Request Headers
Date: Mon, 12 Jul 2021 13:11:34 GMTContent-Type: application/jsonAuthorization: Signature keyId="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",algorithm="hmac-sha256",headers="(request-target) host date content-type content-length",signature="8WaJl5RGH88c7zJJ7Ls5/1mexev6K35MurIZnI0sEKo="Content-Length: 171User-Agent: PostmanRuntime/7.28.1Accept: */*Cache-Control: no-cachePostman-Token: 92636f9a-73f8-4d51-b8c0-a0fee5ea9d53Host: api-worldcheck.refinitiv.comAccept-Encoding: gzip, deflate, brConnection: keep-alive
Request Body
{ "entityType": "ORGANISATION", "groupId": "xxxxxxxxxxxxxxxxxxxxxxxxx", "providerTypes": [ "WATCHLIST" ], "name": "Lajnat ul Masa Eidatul Afghaniab" }
0 -
@cadyh ,
Thanks for the details.
Can you please confirm if you are using the same format as above of the request payload in the code and postman? Or are the formats getting changed in anyway?
0 -
No, the format is not changed. They are both from WorldCheck sample code. The have changedthe name and added this code "ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;" from answer in other question to solve the problem with the error "Could not create secured channel". I have tried with different names.
I noticed there is a space between post and gatewayurl that I removed somehow( must be when I tried different things to solve this problem) in the dataToSign variable. I added back in. This is now the same as the sample code (below)
UTF8Encoding encoding = new UTF8Encoding();
byte[] byte1 = encoding.GetBytes(postData);
string msg = postData;
string dataToSign = "(request-target): post " + gatewayurl + "cases\n" +
"host: " + gatewayhost + "\n" + // no https only the host name
"date: " + date + "\n" + // GMT date as a string
"content-type: " + "application/json" + "\n" +
"content-length: " + byte1.Length + "\n" +
msg;
I now get a different error. With the space back in I now get error 500 Internal Server Error.
This is the dataToSign value: "(request-target): post /v2/cases\nhost: api-worldcheck.refinitiv.com\ndate: Tue, 13 Jul 2021 20:54:17 GMT\ncontent-type: application/json\ncontent-length: 138\n{\"entityType\":\"ORGANISATION\",\"groupId\":\"xxxxxxxxxxxxxxxxxxxxxxx\",\"provideTypes\":[\"WATCHLIST\"],\"name\":\"Lajnat ul Masa Eidatul Afghaniab\"}"
I see the postman body has new line and indented so I removed them all. The content length from postman is now show 139, it is 1 longer than the content length from C# code. I can't find where that 1 different in length is. Is it really the cause of the issue?
Request HeadersDate: Tue, 13 Jul 2021 20:51:43 GMTContent-Type: application/jsonAuthorization: Signature keyId="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",algorithm="hmac-sha256",headers="(request-target) host date content-type content-length",signature="e/Sxhitb/KbbSdt3Qqml0KsPbIGMLR0XwzWT6eCm5Cs="Content-Length: 139User-Agent: PostmanRuntime/7.28.1Accept: */*Cache-Control: no-cachePostman-Token: 4a30df6a-6450-400c-afa7-65210b4a92eaHost: api-worldcheck.refinitiv.comAccept-Encoding: gzip, deflate, brConnection: keep-alive0
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
- 280 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
- 720 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 中文论坛