I've been trying to set up a flow to look at a certain website, extract a value and then return a colour based on what was on the website. That bit is all fine, but it's the next step where I need to then display this info on a webpage to be viewed by another program.
At the moment the colour it is returning is blue. I need this to be displayed on the webpage in the format:
[blue]
Currently I can either get it to be displayed as:
blue
or
["blue"]
but never [blue]. In some instances it would need to be multiple colours as well in the format [blue , white], depending on the info from the website.
I've got my flow below - I'm pretty sure the issues are in the last few sections, but not sure where.
Any help would be greatly appreciated.
Thanks
Mike
[{"id":"27f0628ce2b73c52","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"eaf43c07ec9fb718","type":"http in","z":"27f0628ce2b73c52","name":"mybin","url":"/mybin","method":"get","upload":false,"swaggerDoc":"","x":70,"y":420,"wires":[["b6ac3483fd5bae4e"]]},{"id":"b6ac3483fd5bae4e","type":"function","z":"27f0628ce2b73c52","name":"getFromGlobal","func":"//var newMsg = RED.util.cloneMessage(msg);\n//msg.payload = JSON.stringify(global.get('bincolour')).replace(\"/\\\"/g\", \"\");\nlet data = global.get(\"bincolour\")\nlet colours = []\n\n// get colours for first week \ndata[0].bins.forEach(bin => colours.push(bin.colour) )\n\n//msg.payload = colours //or \nmsg.payload = colours.join()\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":260,"y":420,"wires":[["fa8ae225fda725b5","9f07250485108c9c"]]},{"id":"d36ea6de71435558","type":"http response","z":"27f0628ce2b73c52","name":"success","statusCode":"200","headers":{},"x":860,"y":440,"wires":[]},{"id":"23961d5cc99df3a1","type":"debug","z":"27f0628ce2b73c52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":220,"wires":[]},{"id":"1b2d275075858684","type":"function","z":"27f0628ce2b73c52","name":"add bin Colors","func":"let weeks = msg.payload.collectionWeeks;\n\n\nweeks.forEach(week => {\n week.bins.forEach(bin => {\n if (bin.type === \"General\") { bin.colour = \"white\" }\n if (bin.type === \"Food\") { bin.colour = \"blue\" }\n if (bin.type === \"Garden\") { bin.colour = \"green\" }\n })\n});\n\nmsg.payload = weeks;\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":280,"wires":[["23961d5cc99df3a1","f15cba3869782ec2"]]},{"id":"26c7883944b69ecb","type":"inject","z":"27f0628ce2b73c52","name":"","props":[{"p":"payload"}],"repeat":"86400","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":110,"y":60,"wires":[["eceb1bf3ac43475d"]]},{"id":"9163284842d130e8","type":"http request","z":"27f0628ce2b73c52","name":"auth req","method":"POST","ret":"txt","paytoqs":"body","url":"https://authwebservice.cardiff.gov.uk/AuthenticationWebService.asmx?op=GetJW","tls":"","persist":true,"proxy":"","authType":"","x":320,"y":140,"wires":[["7ca2248be14e34e7"]]},{"id":"eceb1bf3ac43475d","type":"function","z":"27f0628ce2b73c52","name":"","func":"msg.headers = {\n \"Content-Length\": \"284\",\n \"Accept-Encoding\": \"gzip, deflate, br\",\n \"Referer\": \"https://www.cardiff.gov.uk/\",\n \"Origin\": \"https://www.cardiff.gov.uk\",\n \"Content-Type\": `text/xml; charset=\"utf-8\"`,\n \"Sec-Fetch-Dest\": \"empty\",\n \"Sec-Fetch-Mode\": \"no-cors\",\n \"Sec-Fetch-Site\": \"same-site\",\n \"Pragma\": \"no-cache\",\n \"Cache-Control\": \"no-cache\"\n}\n\nmsg.payload = `<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetJWT xmlns='http://tempuri.org/' /></soap:Body></soap:Envelope>`\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":180,"y":140,"wires":[["9163284842d130e8"]]},{"id":"7ca2248be14e34e7","type":"xml","z":"27f0628ce2b73c52","name":"","property":"payload","attr":"","chr":"","x":450,"y":140,"wires":[["065ddccc88de3dbd"]]},{"id":"065ddccc88de3dbd","type":"function","z":"27f0628ce2b73c52","name":"","func":"let access_token = JSON.parse(msg.payload[\"soap:Envelope\"][\"soap:Body\"][0].GetJWTResponse[0].GetJWTResult).access_token\n\nmsg.payload = {\n \"systemReference\": \"web\",\n \"language\": \"eng\",\n \"uprn\": 10094241834 // code for address ?? you need to find it from browser\n}\n\nmsg.headers = {\n \"Authorization\": `Bearer ${access_token}`\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":180,"y":220,"wires":[["f5b04ea719012ec8"]]},{"id":"f5b04ea719012ec8","type":"http request","z":"27f0628ce2b73c52","name":"WasteCollection req","method":"POST","ret":"obj","paytoqs":"body","url":"https://api.cardiff.gov.uk/WasteManagement/api/WasteCollection","tls":"","persist":false,"proxy":"","authType":"","x":360,"y":220,"wires":[["1b2d275075858684","83c64eed6c4b6c2d"]]},{"id":"83c64eed6c4b6c2d","type":"debug","z":"27f0628ce2b73c52","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":100,"wires":[]},{"id":"f15cba3869782ec2","type":"function","z":"27f0628ce2b73c52","name":"SaveToGlobal","func":"global.set('bincolour', msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":880,"y":360,"wires":[[]]},{"id":"9f07250485108c9c","type":"template","z":"27f0628ce2b73c52","name":"DisplayOnPage","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}}","output":"str","x":640,"y":440,"wires":[["d36ea6de71435558","41639f5de536fadd"]]},{"id":"41639f5de536fadd","type":"debug","z":"27f0628ce2b73c52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":520,"wires":[]},{"id":"fa8ae225fda725b5","type":"debug","z":"27f0628ce2b73c52","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":580,"wires":[]},{"id":"178904c8a0b3fdc4","type":"json","z":"27f0628ce2b73c52","name":"","property":"payload","action":"","pretty":false,"x":470,"y":400,"wires":[[]]},{"id":"42184694c94cc7c4","type":"function","z":"27f0628ce2b73c52","name":"getFromGlobal","func":"//var newMsg = RED.util.cloneMessage(msg);\n//msg.payload = JSON.stringify(global.get('bincolour')).replace(\"/\\\"/g\", \"\");\nmsg.payload = global.get(\"bincolour\")\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":240,"y":520,"wires":[[]]}]