For a deeper look into our DataScope Select SOAP API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials

question

Upvotes
Accepted
966 11 19 26

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?

dss-rest-apidatascope-selectdssrest-api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Hi Neil,

Did adding the header solve your problem?

Upvote
Accepted
465 3 5 3

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
   }
}

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

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

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":"

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.

OK thanks.

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

test.zip (1.1 KiB)

Thanks Rick, that worked for me

Upvotes
1.1k 4 3 5

What was in the body of that reply?

"content-length":"2356"

It should be a Validation error: InvalidArgumentNullException: Value cannot be null. ParameterName=ExtractionRequest

Can you capture the actual wire packet you are sending in - I cannot see why that was null from your code.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

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.<ExecuteA
Upvotes
1.1k 4 3 5

That is not what I would have expected - we need to see the body of your POST.

@Troy Dalldorf or @Henry Jue - can you take this up and run with it? I am technically out and now leaving for a long weekend, back on Tuesday.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

The body is there in the original question

Click below to post an Idea Post Idea