How to add an object to the Node-RED msg.payload

Hi.
I'm failing in adding elements to the payload object, simply because the payload iself it not declared at the beginning of the flow as object.
I've found many other users facing this problem, and while I understood the problem itself, is totally unclear on how to solve it.

This Stackoverflow is the closest solution I've found, but failing to implement, while previous threads on the forum weren't fully understandable (at least to me)

I have documented my problem here, is anybody can give a look I'll be super grateful.
Thanks in advance.

[{"id":"bf60b8.b136b748","type":"http request","z":"fab6f208.77334","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://www.freeforexapi.com/api/live?pairs={{payload.from}}{{payload.to}}","tls":"","persist":false,"proxy":"","authType":"","x":650,"y":560,"wires":[["f0831588.228b58"]]},{"id":"e4cab682.a14598","type":"ui_text_input","z":"fab6f208.77334","name":"","label":"","tooltip":"","group":"b750e8e.87cde18","order":3,"width":"4","height":"1","passthru":true,"mode":"number","delay":300,"topic":"payload.value","x":130,"y":180,"wires":[["a1973af7.20f3f"]]},{"id":"c60c34d1.257e","type":"ui_dropdown","z":"fab6f208.77334","name":"","label":"from","tooltip":"","place":"Select option","group":"b750e8e.87cde18","order":1,"width":"4","height":"1","passthru":true,"multiple":false,"options":[{"label":"EUR","value":"EUR","type":"str"},{"label":"USD","value":"USD","type":"str"},{"label":"GBP","value":"GBP","type":"str"}],"payload":"","topic":"from","x":150,"y":120,"wires":[["40f2b184.591cb"]]},{"id":"15137eaa.baaab9","type":"ui_dropdown","z":"fab6f208.77334","name":"","label":"to","tooltip":"","place":"Select option","group":"b750e8e.87cde18","order":1,"width":"4","height":"1","passthru":true,"multiple":false,"options":[{"label":"EUR","value":"EUR","type":"str"},{"label":"USD","value":"USD","type":"str"},{"label":"GBP","value":"GBP","type":"str"}],"payload":"","topic":"to","x":150,"y":240,"wires":[["81cca0e3.4dd0f8"]]},{"id":"628853bf.66bfd4","type":"ui_button","z":"fab6f208.77334","name":"","group":"b750e8e.87cde18","order":0,"width":"1","height":"1","passthru":false,"label":"covert","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"payload","x":110,"y":420,"wires":[["90dad6c6.cc6f08"]]},{"id":"f0831588.228b58","type":"debug","z":"fab6f208.77334","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":560,"wires":[]},{"id":"81cca0e3.4dd0f8","type":"change","z":"fab6f208.77334","name":"","rules":[{"t":"set","p":"to","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":240,"wires":[[]]},{"id":"a1973af7.20f3f","type":"change","z":"fab6f208.77334","name":"","rules":[{"t":"set","p":"value","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":180,"wires":[[]]},{"id":"40f2b184.591cb","type":"change","z":"fab6f208.77334","name":"","rules":[{"t":"set","p":"from","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":120,"wires":[[]]},{"id":"24e9e8eb.081cc8","type":"debug","z":"fab6f208.77334","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":400,"wires":[]},{"id":"93e6edc4.7fc7","type":"inject","z":"fab6f208.77334","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":460,"wires":[["90dad6c6.cc6f08"]]},{"id":"90dad6c6.cc6f08","type":"change","z":"fab6f208.77334","name":"","rules":[{"t":"set","p":"payload.to","pt":"msg","to":"to","tot":"flow"},{"t":"set","p":"payload.from","pt":"msg","to":"from","tot":"flow"},{"t":"set","p":"payload.value","pt":"msg","to":"value","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":440,"wires":[["24e9e8eb.081cc8"]]},{"id":"79281847.c5e318","type":"inject","z":"fab6f208.77334","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"{}","payloadType":"json","x":630,"y":240,"wires":[["6f713608.c86e28"]]},{"id":"6f713608.c86e28","type":"debug","z":"fab6f208.77334","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":240,"wires":[]},{"id":"3d4263c2.ced29c","type":"comment","z":"fab6f208.77334","name":"Dropdown Payloads that are moved to the Flow Context","info":"","x":240,"y":60,"wires":[]},{"id":"dc148259.1f642","type":"comment","z":"fab6f208.77334","name":"Setting the Payload as Object when Triggering the flow","info":"","x":740,"y":180,"wires":[]},{"id":"e0287405.264198","type":"comment","z":"fab6f208.77334","name":"Trying to see all 3 different dropdown payload in the same object","info":"","x":270,"y":360,"wires":[]},{"id":"a3a31007.ff02f","type":"comment","z":"fab6f208.77334","name":"expecting two payload values to populate this http request","info":"","x":750,"y":500,"wires":[]},{"id":"b750e8e.87cde18","type":"ui_group","name":"cambia-valuta","tab":"414a2b76.3ce37c","order":1,"disp":true,"width":"6","collapse":false},{"id":"414a2b76.3ce37c","type":"ui_tab","name":"cambia-valuta","icon":"dashboard","disabled":false,"hidden":false}]

You don't appear to have implemented the suggestion in the stackoverflow link, which is to set msg.payload to an empty object first. Like this

Thanks Colin.
I thoughts the inject node that was creating an empty object at the very beginning of the flow was enough!

Now it works fine

I don't see an inject node creating an empty object in the flow you posted. In fact you could instead solve the problem by making the covert button send an empty object, but it is probably clearer to put it in the Change node.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.