I’m trying to create a forEach loop that creates a http batch request in NodeRed. The formatting of the payload needs to be a JSON object, my function node keeps indicating that I need ; instead of : in the forEach loop at the end. I know it’s probably something nooby stupid but I can’t seem to figure out what my issue is.
var ipaddr = msg.payload.ipddr[0]
var credentials = msg.payload.auth[0]
var base64 = new Buffer(credentials).toString('base64')
const nameArray = msg.payload.nameArray
const descriptionArray = msg.payload.descriptionArray
const areaArray = msg.payload.areaArray
const useTypeArray = msg.payload.useTypeArray
const addressArray = msg.payload.addressArray
const yearBuiltArray = msg.payload.yearBuiltArray
var createMsg = {};
createMsg.method = "POST";
createMsg.headers = {};
createMsg.headers['authorization'] = 'basic ' + base64;
createMsg.headers['Content-Type'] = "application/JSON";
createMsg.url = "https://" + ipaddr + "/v2/batch";
var body =
{
"requests":[
nameArray.forEach((y, i) => {
{
"id": nameArray[i]
"url": "/api/rest/v2/services/site/buildings/" + nameArray[i]
"key": name
"use-type": useTypeArray[i]
"area": areaArray[i]
"address": addressArray[i]
"description": descriptionArray[i]
"year-built": yearBuiltArray[i]
},
}
)
]
};
createMsg.payload = body;
node.send(createMsg);
return null;
I would expect it to be ok with each entry in the last for loop like “area”: areaArray[i]