In a function, I have to insert a string into a data array, that is part of axios request call:
var obj1 = JSON.parse(payload);
axios.request({
url: inUrl,
method: "POST",
auth: {
username: auth,
password: pass
},
headers: { 'content-type': 'application/json' },
data: {
"success": inState,
"fails": inCount,
obj1
}
}).then(res => {
//console.log(res);
console.log("bucket commopn response: "+ res.status);
return "success";
}).catch(error => {
console.log(error);
console.log("bucket error reponse: " + error.response.status);
return "error";
});
payload is a pure string with the content:
{"branch":"CPL-1223"}
This was created from an object with
var payload = JSON.stringify(req.body.responsePayload);
How can I insert the new object into
data: {
"success": inState,
"fails": inCount,
obj1
}
To make a valid call? Because currently, whatever I do, I get from the Axios server a invalid body, if I make hand call
data: {
"success": inState,
"fails": inCount,
"branch":"CPL-1223"
}
I get a success back. What is my fault?
...obj1instead of justobj1in data.