DSS REST API StatusCode 400 response
Hi, I am trying to call the DSS REST API with the following Javascript code
exports.getEOD = function(token, success, failure) {
var https = require('https');
var url = 'hosted.datascopeapi.reuters.com';
var path = "/RestApi/v1/Extractions/ExtractWithNotes";
var response = ''
var options = {
hostname: url,
path: path,
method: 'POST',
headers: {
'Authorization': 'Token ' + token,
'X-Client-Version': 'restapiv1.10.2.884.0',
'Prefer': 'respond-async, wait=5'
}
};
var postData = JSON.stringify({
"ExtractionRequest": {
"@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.EndOfDayPricingExtractionRequest",
"ContentFieldNames": [
"Asset Status",
"Asset Type",
"Bid Price",
"Currency Code",
"CUSIP",
"File Code",
"Ask Price",
"High Price",
"Low Price",
"Mid Price",
"Volume",
"Net Asset Value",
"Offer Price",
"Official Close Price",
"Open Price",
"Previous Close Price",
"RIC",
"Security Description",
"SEDOL",
"Ticker",
"Trade Date"
],
"IdentifierList": {
"@odata.type": "#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.InstrumentIdentifierList",
"InstrumentIdentifiers": [
{
"Identifier": "191216100",
"IdentifierType": "Cusip"
},
{
"Identifier": "2005973",
"IdentifierType": "Sedol"
},
{
"Identifier": "AAPL.OQ",
"IdentifierType": "Ric"
}
]
},
"Condition": null
}
})
var req = https.get(options, function(res) {
if (res.statusCode == 200) {
res.setEncoding('utf8');
res.on('data', function(chunk) {
response = response + chunk
});
res.on('end', function() {
success(response)
})
}
else{
console.log('statusCode: ' + res.statusCode);
failure(JSON.stringify(res.headers))
}
});
req.on('error', function(e) {
failure(e.message)
});
console.log(postData)
req.write(postData);
req.end();
}
I get the following response
statusCode: 400
EOD Error: {"cache-control":"no-cache","pragma":"no-cache","content-type":"application/json; odata.metadata=minimal; odata.streaming=true","expires":"-1","server":"Microsoft-IIS/7.5","odata-version":"4.0","x-request-execution-correlation-id":"e26efcaf-e571-4816-92b1-07e232a7b6cd","x-app-id":"Custom.RestApi","x-app-version":"10.4.77.0","x-powered-by":"ASP.NET","date":"Fri, 04 Mar 2016 14:56:37 GMT","content-length":"2356"}
What could the problem be?
Best Answer
-
Neil, the problem does not appear to be with the body of the request, but rather the encoding of the body. I copied the body you provided and successfully submitted the request with a 200 response and the body containing the expected data. However, when I encoding the body as UTF8 I see the same error you are. The problem is that the body is formatted as UTF8 while there is no indication of UTF8 encoding in the header. Can you try adding the following header:
Content-Type: application/json; odata=minimalmetadata; charset=utf-8
This also works: Content-Type: application/json; charset=utf-8
Headers I used:
Accept: application/json; odata.metadata=minimal
Content-Type: application/json; odata=minimalmetadata; charset=utf-8
Authorization: Token <your_token_here><br>Body I used:
{
"ExtractionRequest":{
"@odata.type":"#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.EndOfDayPricingExtractionRequest",
"ContentFieldNames":[
"Asset Status",
"Asset Type",
"Bid Price",
"Currency Code",
"CUSIP",
"File Code",
"Ask Price",
"High Price",
"Low Price",
"Mid Price",
"Volume",
"Net Asset Value",
"Offer Price",
"Official Close Price",
"Open Price",
"Previous Close Price",
"RIC",
"Security Description",
"SEDOL",
"Ticker",
"Trade Date"
],
"IdentifierList":{
"@odata.type":"#ThomsonReuters.Dss.Api.Extractions.ExtractionRequests.InstrumentIdentifierList",
"InstrumentIdentifiers":[
{
"Identifier":"191216100",
"IdentifierType":"Cusip"
},
{
"Identifier":"2005973",
"IdentifierType":"Sedol"
},
{
"Identifier":"AAPL.OQ",
"IdentifierType":"Ric"
}
]
},
"Condition":null
}
}0
Answers
-
What was in the body of that reply?
"content-length":"2356"
It should be a Validation error: InvalidArgumentNullException: Value cannot be null.
ParameterName=ExtractionRequestCan you capture the actual wire packet you are sending in - I cannot see why that was null from your code.
0 -
Body was
"error":{
"code":"","message":"Malformed request payload. Line 1, Char 1: expected valid json array or json object","innererror":{
"message":"Malformed request payload. Line 1, Char 1: expected valid json array or json object","type":"ThomsonReuters.Dss.Core.Exceptions.BadRequestException","stacktrace":" at .......System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteA0 -
-
The body is there in the original question
0 -
I was able to reproduce the problem. It is not the body that is the problem, but rather the encoding of the body. The body is encoded as UTF8 while there is nothing in the header to indicate the encoding. Unicode encoded as UTF8 adds a couple of special characters in front which is where the malformed JSON message is coming from. Can you try adding the following header?
Content-Type: application/json; odata=minimalmetadata; charset=utf-8
0 -
Hi Neil,
Did adding the header solve your problem?
0 -
Hi, I have added the header
'Content-Type': 'application/json, odata=minimalmetadata, charset=utf-8'
This still gives me a status 400 error with the following body
"error":{
"code":"","message":"Value cannot be null.\r\nParameterName=ExtractionRequest","innererror":{
"message":"Value cannot be null.\r\nParameterName=ExtractionRequest","type":"ThomsonReuters.Dss.Core.Exceptions.InvalidArgumentNullException","stacktrace":"0 -
I am sorry for the delay - both Troy and I are on vacation today. I will be back in the office on Monday.
It definitely seems like it cannot make a valid object out of your ExtractionRequest JSON even though it looks fine to me.
I will forward your code on to another developer asking them to take a look tomorrow so maybe we can have an answer for you by Monday.
0 -
OK thanks.
0 -
1: You added "Content-Type" heaader: 'Content-Type': 'application/json, odata=minimalmetadata, charset=utf-8' but that's wrong as it should be: 'Content-Type': 'application/json; odata=minimalmetadata; charset=utf-8' NOTE: You needed a ";" instead of ","
2: You are calling https.get(), but should be calling https.request()
I have attached a simplified version to this comment.test.zip
0 -
Thanks Rick, that worked for me
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
- 688 Datastream
- 1.4K DSS
- 625 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
- 557 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
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 276 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 23 RDMS
- 1.9K Refinitiv Data Platform
- 695 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
- 105 UPA
- 194 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 92 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛