My nodeJS script needs to make a put/post action to provide an xml file as payload.
However it keeps on failing here saying :
Object.keys(data).forEach(function(key) {
^
TypeError: Object.keys called on non-object
at Function.keys (native)
at Object.exports.getBodyString
printing data to stdout gives me the whole xml file in text. The type of data is string.
exports.getBodyString = function(data) { var body = '';
if(data && !this.isEmpty(data)){
Object.keys(data).forEach(function(key) {
var val = data[key];
if (exports.isArray(val)) {
for (var i=0; i<val.length; i++) {
body += key + '[]=' + encodeURIComponent(val[i]) + '&';
}
} else {
body += key + '=' + encodeURIComponent(val) + '&';
}
});
return body; } return null; };
What I try to recreate is:
curl -X POST -H "Content-Type: application/xml" -d @config.xml "http://localhost:11000/oozie/v1/jobs?action=start"
to conclude How do I properly parse a while xml file (indents and new lines and everything) to proper JSON? I'm struggling with xml2js. That seems to return [Object], [Object], ... instead of proper values.
I can still just deliver the xml file and skip the whole function when using
headers: {"content-type": "application/xml"}
instead of
headers: {"content-type": "application/x-www-form-urlencoded"},