How to send xml post params with the help of node.js

12,546

Try this :-

    var request = require("request");
var utf8 = require('utf8');



var abc = '<ENVELOPE>
          <HEADER>
                    <VERSION>1</VERSION>
                    <STATUS>1</STATUS>
          </HEADER>
</ENVELOPE><ENVELOPE><HEADER><TALLYREQUEST>Export Data</TALLYREQUEST></HEADER><BODY><EXPORTDATA><REQUESTDESC><REPORTNAME>Stock Summary</REPORTNAME><STATICVARIABLES><EXPLODEFLAG>Yes</EXPLODEFLAG><SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><ACCOUNTTYPE>All Inventory Masters</ACCOUNTTYPE></STATICVARIABLES></REQUESTDESC></EXPORTDATA></BODY></ENVELOPE>';

request.post({
    url:"http://192.168.1.148",
    port: 9000,
    method:"POST",
    headers:{
        'Content-Type': 'application/xml',
    },
     body: abc
},
function(error, response, body){
    console.log(response.statusCode);
    console.log(body);
    console.log(error);
});

Basically add versioning of tally in your xml. It won't show any error and xml will be synced

Share:
12,546

Related videos on Youtube

neerajUdai
Author by

neerajUdai

AVP Engineering, Trell

Updated on June 04, 2022

Comments

  • neerajUdai
    neerajUdai over 1 year

    Trying to post XML data to following url via node js:-

    var request = require("request");
    var utf8 = require('utf8');
    
    
    
    var abc = '<ENVELOPE><HEADER><TALLYREQUEST>Export Data</TALLYREQUEST></HEADER><BODY><EXPORTDATA><REQUESTDESC><REPORTNAME>Stock Summary</REPORTNAME><STATICVARIABLES><EXPLODEFLAG>Yes</EXPLODEFLAG><SVEXPORTFORMAT>$$SysName:XML</SVEXPORTFORMAT><ACCOUNTTYPE>All Inventory Masters</ACCOUNTTYPE></STATICVARIABLES></REQUESTDESC></EXPORTDATA></BODY></ENVELOPE>';
    
    request.post({
        url:"http://192.168.1.148",
        port: 9000,
        method:"POST",
        headers:{
            'Content-Type': 'application/xml',
        },
         body: abc
    },
    function(error, response, body){
        console.log(response.statusCode);
        console.log(body);
        console.log(error);
    });
    

    But interpreter is showing following error:-

    console.log(response.statusCode);
                        ^
    TypeError: Cannot read property 'statusCode' of undefined
    at Request._callback (C:\Users\bliscar\prog10.js:18:25)
    at self.callback (C:\Users\bliscar\node_modules\request\request.js:198:22)
    at Request.emit (events.js:107:17)
    at Request.onRequestError (C:\Users\bliscar\node_modules\request\request.js:
    

    861:8) at ClientRequest.emit (events.js:107:17) at Socket.socketErrorListener (_http_client.js:271:9) at Socket.emit (events.js:107:17) at net.js:459:14 at process._tickCallback (node.js:355:11)

    Not able to work out what's the issue. Please help to resolve.

    • Quentin
      Quentin over 8 years
      "But interpreter is showing some error." — Have you considered telling us what that error might be?
    • neerajUdai
      neerajUdai over 8 years
      @Quentin : Added the error, Can you please help me out with the issue as it's pretty urgent.
  • Aedric
    Aedric almost 4 years
    i I like this code. Quick question. What does this "var utf8 = require('utf8');" do?