Friday 14 April 2017

reading REST POST response node.js

I am able to test a post call in rest client which shows headers as:

Cache-Control: no-cache, no-store, must-revalidate
Connection: keep-alive
Content-Encoding: gzip
Content-Language: en
Content-Length: 49
Content-Type: application/json
Date: Fri, 14 Apr 2017 21:05:42 GMT

my code to invoke the post is as follows:

var https = require('https');
... var jsonObject = JSON.stringify({
            "Name" : optyName
        });

        // prepare the header
        var postheaders = {
            'Content-Type' : 'application/vnd.oracle.adf.resourceitem+json',
            'authorization' : 'Basic am9obi5kdW5iYXI6dnBoODk1ODM=',
            gzip: true
        };

        // the post options
        var optionspost = {
            host : 'myhost',
            port : 443,
            path : '/salesApi/resources/11.1.11/opportunities?fields=OptyId&onlyData=true',
            method : 'POST',
            headers : postheaders,
        };

        // do the POST call
        var reqPost = https.request(optionspost, function(error,response,body) {
             console.log('the decoded data is: ' + body)
         });

  reqPost.write(jsonObject);
        reqPost.end();
}

However i get the printed stuff:

the decoded data is: undefined



via Vik

No comments:

Post a Comment