Discover Refinitiv
MyRefinitiv Refinitiv Perspectives Careers
Created with Sketch.
All APIs Questions & Answers  Register |  Login
Ask a question
  • Questions
  • Tags
  • Badges
  • Unanswered
Search:
  • Home /
  • DSS /
avatar image
REFINITIV
Question by Neil Shah · Mar 04, 2016 at 10:06 AM · restrest_apidss-sdk

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?

People who like this

0 Show 1
Comment
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
REFINITIV
Troy Dalldorf · Mar 07, 2016 at 11:18 AM 0
Share

Hi Neil,

Did adding the header solve your problem?

3 Replies

  • Sort: 
avatar image
REFINITIV
Best Answer
Answer by Troy Dalldorf · Mar 04, 2016 at 12:42 PM

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

Comment
Andy Rhodes

People who like this

1 Show 6 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
REFINITIV
Troy Dalldorf · Mar 04, 2016 at 03:41 PM 0
Share

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

avatar image
REFINITIV
Neil Shah ♦♦ · Mar 15, 2016 at 12:16 PM 0
Share

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

avatar image
REFINITIV
Rick Weyrauch Neil Shah ♦♦ · Mar 17, 2016 at 04:25 PM 0
Share

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.

avatar image
REFINITIV
Neil Shah ♦♦ · Mar 18, 2016 at 08:15 AM 0
Share

OK thanks.

avatar image
REFINITIV
Rick Weyrauch Neil Shah ♦♦ · Mar 21, 2016 at 11:16 AM 0
Share

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)
avatar image
REFINITIV
Neil Shah ♦♦ · Mar 22, 2016 at 10:51 AM 0
Share

Thanks Rick, that worked for me

avatar image
REFINITIV
Answer by Rick Weyrauch · Mar 04, 2016 at 10:46 AM

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.

Comment

People who like this

0 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
REFINITIV
Neil Shah ♦♦ · Mar 04, 2016 at 11:13 AM 0
Share

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
avatar image
REFINITIV
Answer by Rick Weyrauch · Mar 04, 2016 at 11:24 AM

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.

Comment

People who like this

0 Show 1 · Share
10 |1500 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

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

avatar image
REFINITIV
Neil Shah ♦♦ · Mar 04, 2016 at 11:28 AM 0
Share

The body is there in the original question

Watch this question

Add to watch list
Add to your watch list to receive emailed updates for this question. Too many emails? Change your settings >
6 People are following this question.

Related Questions

What content is available in the DSS GUI but not in the REST API?

Use chain rics in the REST API

​How can I get API token for access to reuters API ?

How to use DSS/REST API examples behind a proxy?

Sample C# code that excludes deleted items when pulling data from DSS Corporate Actions table

  • Feedback
  • Copyright
  • Cookie Policy
  • Privacy Statement
  • Terms of Use
  • Careers
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Alpha
  • App Studio
  • Block Chain
  • Bot Platform
  • Calais
  • Connected Risk APIs
  • DSS
  • Data Fusion
  • Data Model Discovery
  • Datastream
  • Eikon COM
  • Eikon Data APIs
  • Elektron
    • EMA
    • ETA
    • WebSocket API
  • Legal One
  • Messenger Bot
  • Messenger Side by Side
  • ONESOURCE
    • Indirect Tax
  • Open PermID
    • Entity Search
  • Org ID
  • PAM
    • PAM - Logging
  • ProView
  • ProView Internal
  • Product Insight
  • Project Tracking
  • Refinitiv Data Platform
    • Refinitiv Data Platform Libraries
  • Rose's Space
  • Screening
    • Qual-ID API
    • Screening Deployed
    • Screening Online
    • World-Check One
    • World-Check One Zero Footprint
  • Side by Side Integration API
  • TR Knowledge Graph
  • TREP APIs
    • CAT
    • DACS Station
    • Open DACS
    • RFA
    • UPA
  • TREP Infrastructure
  • TRIT
  • TRKD
  • TRTH
  • Thomson One Smart
  • Transactions
    • REDI API
  • Velocity Analytics
  • Wealth Management Web Services
  • World-Check Data File
  • Explore
  • Tags
  • Questions
  • Badges