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-alive
0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛