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

  • Troy Dalldorf
    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
    }
    }

Answers