# Msg.object to msg.url

**URL:** <https://discourse.nodered.org/t/msg-object-to-msg-url/31929>\
**Category:** General\
**Created:** [24 August 2020 04:59 UTC](https://discourse.nodered.org/t/msg-object-to-msg-url/31929 "2020-08-24T04:59:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxx](https://avatars.discourse-cdn.com/v4/letter/f/8e8cbc/32.png) [@fxx](https://discourse.nodered.org/u/fxx)\
**Post date:** [24 August 2020 04:59 UTC](https://discourse.nodered.org/t/msg-object-to-msg-url/31929/1 "2020-08-24T04:59:40Z")

</div>

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?

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [24 August 2020 05:43 UTC](https://discourse.nodered.org/t/msg-object-to-msg-url/31929/2 "2020-08-24T05:43:45Z")

</div>

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 :

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [24 August 2020 05:44 UTC](https://discourse.nodered.org/t/msg-object-to-msg-url/31929/3 "2020-08-24T05:44:17Z")

</div>

Try it like this.

```auto
[{"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)

---

<div class="post-metadata">

**Author:** ![fxx](https://avatars.discourse-cdn.com/v4/letter/f/8e8cbc/32.png) [@fxx](https://discourse.nodered.org/u/fxx)\
**Post date:** [24 August 2020 06:01 UTC](https://discourse.nodered.org/t/msg-object-to-msg-url/31929/4 "2020-08-24T06:01:50Z")

</div>

Thank you.  
All of them work

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 October 2020 06:01 UTC](https://discourse.nodered.org/t/msg-object-to-msg-url/31929/5 "2020-10-23T06:01:57Z")

</div>

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