Msg.object to msg.url

Hi there.
I got stuck changing msg.url (object) to msg.url acceptable in http request node.
What should I set msg.url to in change node?
Can I return msg.url from the function as a string?

[{"id":"ace7ea29.4b43c","type":"tab","label":"FX","disabled":false,"info":""},{"id":"ad559c0a.861c5","type":"debug","z":"ace7ea29.4b43c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1930,"y":420,"wires":[]},{"id":"204b5f33.e44e48","type":"http request","z":"ace7ea29.4b43c","name":"USDJPY","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":1580,"y":640,"wires":[["ad559c0a.861c5"]]},{"id":"5b29175c.b6a8c","type":"function","z":"ace7ea29.4b43c","name":"","func":"var topic = msg.payload;\nfrom = topic.substr(0, 3);\nvar to = msg.payload;\nto = to.substr(3, 6);\n\nvar url = \"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=\"+from+\"&to_currency=\"+to+\"&apikey=7NLFVEIFPWMVFSVJ\";\n\nmsg.payload = url;\nmsg.url = {payload: url};\nmsg.topic = {payload: url};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1120,"y":640,"wires":[["5c1e3d60.1d97cc","ad559c0a.861c5"]]},{"id":"47f7762b.72969","type":"inject","z":"ace7ea29.4b43c","name":"","props":[{"p":"url","v":"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=USD&to_currency=JPY&apikey=demo","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":1310,"y":740,"wires":[["204b5f33.e44e48"]]},{"id":"bc57ee79.8b1118","type":"inject","z":"ace7ea29.4b43c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"USDJPY","payloadType":"str","x":920,"y":640,"wires":[["5b29175c.b6a8c"]]},{"id":"5c1e3d60.1d97cc","type":"change","z":"ace7ea29.4b43c","name":"","rules":[{"t":"set","p":"url","pt":"msg","to":"msg.url","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1310,"y":640,"wires":[["204b5f33.e44e48"]]}]

Hi,

the logic in your function is correct with some changes .. and since you are using a function there is no need for a change node in this case.

See modified flow :

[{"id":"10a7acb9.f269cb","type":"debug","z":"be60d33d.d488e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1310,"y":180,"wires":[]},{"id":"734cfa1d.1c1f14","type":"http request","z":"be60d33d.d488e","name":"USDJPY","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":1580,"y":260,"wires":[["88df9da2.cf9988"]]},{"id":"4074186.7b527e8","type":"function","z":"be60d33d.d488e","name":"","func":"var from = msg.payload;\nfrom = from.substr(0, 3);\nvar to = msg.payload;\nto = to.substr(3, 6);\n\nvar url = `https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=${from}&to_currency=${to}&apikey=7NLFVEIFPWMVFSVJ`;\n\nmsg.url = url;\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1160,"y":260,"wires":[["10a7acb9.f269cb","734cfa1d.1c1f14"]]},{"id":"80e5dd81.e8f1b8","type":"inject","z":"be60d33d.d488e","name":"","props":[{"p":"url","v":"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=USD&to_currency=JPY&apikey=demo","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"str","x":1310,"y":360,"wires":[[]]},{"id":"b6385928.7a1c","type":"inject","z":"be60d33d.d488e","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"USDJPY","payloadType":"str","x":920,"y":260,"wires":[["4074186.7b527e8"]]},{"id":"88df9da2.cf9988","type":"debug","z":"be60d33d.d488e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1750,"y":180,"wires":[]}]

Try it like this.

[{"id":"4472861.09e8b78","type":"http request","z":"4a3c9d15.ba840c","name":"USDJPY","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"","x":1236,"y":648,"wires":[["e79e441a.05c5f8"]]},{"id":"c3916ad2.fdfbd8","type":"function","z":"4a3c9d15.ba840c","name":"","func":"topic = msg.payload;\nfrom = topic.substr(0, 3);\nto = topic.substr(3, 6);\n\nvar url = \"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=\"+from+\"&to_currency=\"+to+\"&apikey=key\";\n\nmsg.url = url\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1068,"y":648,"wires":[["4472861.09e8b78","80c1cfd6.5eb248"]]},{"id":"ef991b4d.2a2fc","type":"inject","z":"4a3c9d15.ba840c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"USDJPY","payloadType":"str","x":924,"y":648,"wires":[["c3916ad2.fdfbd8"]]},{"id":"e79e441a.05c5f8","type":"debug","z":"4a3c9d15.ba840c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1394,"y":648,"wires":[]},{"id":"80c1cfd6.5eb248","type":"debug","z":"4a3c9d15.ba840c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1226,"y":576,"wires":[]}]

sidenote - change the API key after this is working or remove it from the flow in your post (to avoid potential abuse)

Thank you.
All of them work