# Use constant with ip address stored in node configuration (http request)

**URL:** <https://discourse.nodered.org/t/use-constant-with-ip-address-stored-in-node-configuration-http-request/63973>\
**Category:** General\
**Tags:** http-request\
**Created:** [15 June 2022 12:50 UTC](https://discourse.nodered.org/t/use-constant-with-ip-address-stored-in-node-configuration-http-request/63973 "2022-06-15T12:50:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nosfreatu](https://avatars.discourse-cdn.com/v4/letter/n/22d042/32.png) [@nosfreatu](https://discourse.nodered.org/u/nosfreatu)\
**Post date:** [15 June 2022 12:50 UTC](https://discourse.nodered.org/t/use-constant-with-ip-address-stored-in-node-configuration-http-request/63973/1 "2022-06-15T12:50:42Z")

</div>

Hi  
I use following flow to control a music streamer by gpio button.

 ![flowgpio](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/5578669ae8945d2fe204fc7d8d8ee17c4d176362.jpeg)

As I use more then one "http request node" and ther will come more, I would like to replace the IP Adress in "http request" node by a variable or constant. Best would be I could edit the adress in dashboard.

Is this possible and when yes how?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 June 2022 12:58 UTC](https://discourse.nodered.org/t/use-constant-with-ip-address-stored-in-node-configuration-http-request/63973/2 "2022-06-15T12:58:19Z")

</div>

> [@nosfreatu](#):
>
> Is this possible and when yes how?

Its in the built in help...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/55292da6f1a2093887eca96a9c6cca5210608178.png)

Basically, clear the node settings URL field, then pass it into the HTTP request via `msg.url`

---

<div class="post-metadata">

**Author:** ![nosfreatu](https://avatars.discourse-cdn.com/v4/letter/n/22d042/32.png) [@nosfreatu](https://discourse.nodered.org/u/nosfreatu)\
**Post date:** [15 June 2022 13:12 UTC](https://discourse.nodered.org/t/use-constant-with-ip-address-stored-in-node-configuration-http-request/63973/3 "2022-06-15T13:12:27Z")

</div>

Thank. What I forgot to mention, my url looks like this

http:// **192.168.1.122:11000** /Preset?id=2 and I only want to replace the bold section.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 June 2022 13:16 UTC](https://discourse.nodered.org/t/use-constant-with-ip-address-stored-in-node-configuration-http-request/63973/4 "2022-06-15T13:16:03Z")

</div>

you can make your `msg.url` whatever you want

e.g.

**function node**...

```auto
msg.url = "http://" + msg.ip + ":" + msg.port + "/Preset?id=2"
return msg.

```

### Or

use a **change node** to contruct the URL

### Or

the **http-request** node itself supports mustache syntax _(again, its in the help)_ but to get you moving...  
set the URL field to `http://{{ip}}:{{port}}/Preset?id=2`

  

NOTE: All of these examples assume the IP is in `msg.ip` and port is in `msg.port`

---

<div class="post-metadata">

**Author:** ![nosfreatu](https://avatars.discourse-cdn.com/v4/letter/n/22d042/32.png) [@nosfreatu](https://discourse.nodered.org/u/nosfreatu)\
**Post date:** [21 June 2022 08:54 UTC](https://discourse.nodered.org/t/use-constant-with-ip-address-stored-in-node-configuration-http-request/63973/5 "2022-06-21T08:54:23Z")

</div>

Thanks

I did following for testing. But the msg.ip and msg.port are not defined in the other flows.  
So I think i have to find a way to make them defined, what needs more to know about the node red  
system, and some study from me.

```auto
[{"id":"482d7c90.87f404","type":"inject","z":"538c0a77.5b11b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":160,"wires":[["5a6d815a.0cef","3d16c25f.6f56ae"]]},{"id":"5a6d815a.0cef","type":"debug","z":"538c0a77.5b11b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":160,"wires":[]},{"id":"3d16c25f.6f56ae","type":"http request","z":"538c0a77.5b11b4","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"http://{{ip}}:{{port}}/Preset?id=2","tls":"","persist":false,"proxy":"","authType":"","x":630,"y":220,"wires":[[]]},{"id":"a67b305f.b5248","type":"ui_button","z":"538c0a77.5b11b4","name":"","group":"81edf5e0.aee808","order":2,"width":0,"height":0,"passthru":false,"label":"Preset2","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":160,"y":240,"wires":[["3d16c25f.6f56ae"]]},{"id":"11da751a.83e30b","type":"change","z":"538c0a77.5b11b4","name":"","rules":[{"t":"set","p":"ip","pt":"msg","to":"192.168.1.122","tot":"str"},{"t":"set","p":"port","pt":"msg","to":"11000","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":40,"wires":[["a1a93a46.e0ac58"]]},{"id":"ad5f4e7f.ea2aa","type":"inject","z":"538c0a77.5b11b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":40,"wires":[["11da751a.83e30b"]]},{"id":"a1a93a46.e0ac58","type":"debug","z":"538c0a77.5b11b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"ip","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":40,"wires":[]},{"id":"17fdbb9.ef44644","type":"inject","z":"538c0a77.5b11b4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":100,"wires":[["7ed59f41.f787"]]},{"id":"7ed59f41.f787","type":"debug","z":"538c0a77.5b11b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"ip","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":100,"wires":[]},{"id":"81edf5e0.aee808","type":"ui_group","name":"Presets","tab":"5b0d07a7.12a4d8","order":2,"disp":true,"width":"6","collapse":false,"className":""},{"id":"5b0d07a7.12a4d8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<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:** [20 August 2022 08:54 UTC](https://discourse.nodered.org/t/use-constant-with-ip-address-stored-in-node-configuration-http-request/63973/6 "2022-08-20T08:54:53Z")

</div>

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