# Send value in a http-request

**URL:** https://discourse.nodered.org/t/send-value-in-a-http-request/17169
**Category:** General
**Created:** [26 October 2019 13:38 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169 "2019-10-26T13:38:11Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![easyE4](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@easyE4](https://discourse.nodered.org/u/easyE4)
#### Post date: [26 October 2019 13:38 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/1 "2019-10-26T13:38:11Z")

</div>

Hi erverybody,  
in the dokumentation for the WebAPI of my controller I find this example:

/api/set/op?op=MW&index=1&val=10

What I want is to make the "val" variable, comming form a slider node.  
Can someone help me with a small example. Please note, that I'm a beginner.

Thanks in advance!

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [26 October 2019 14:41 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/2 "2019-10-26T14:41:00Z")

</div>

in javascript you can use `+` to join variables

eg msg.payload = “the result is” + msg.result

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [26 October 2019 14:53 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/3 "2019-10-26T14:53:01Z")

</div>

> [@easyE4](#):
>
> make the "val" variable, comming form a slider node.

Hi Ralf (@easyE4),  
If I where you I would do it like this:

- add a http-request node to your flow, where you can enter your url.
- in the url replace "var" by "{{var}}" to have a **Mustache** syntax. See the [cookbook](https://cookbook.nodered.org/http/set-query-string) for an example.
- then the dashboard slider node should be wired (with some other nodes in between?) to the input of your http-request node to inject messages, whose data can be used for the Mustache variables.

Unfortunately I'm typing on my phone, so cannot give you an example flow...  
Bart

---

<div class="post-metadata">

### Author: ![easyE4](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@easyE4](https://discourse.nodered.org/u/easyE4)
#### Post date: [26 October 2019 16:57 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/4 "2019-10-26T16:57:32Z")

</div>

462/5000

I'm afraid I need a little more help. Maybe I did not put my question right.  
I want to pass a setpoint to my PLC controller, which controls a frequency converter.  
For a bit variable the http-request node looks like in the picture. There the value is fixed. Either 0 or 1.

![node-red-flow-boolean](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/44bf64c4c75f0830372c1b9bb8ce3c39f755c649.jpeg)

Now I want to transfer a number generated by the slider in the dashboard, for example 0-100.

/ api / set / op? Op = MW & index = 12 & val = setpoint

So my question is, how can I fill "setpoint" with the value from the silider.

Ralf

---

<div class="post-metadata">

### Author: ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)
#### Post date: [26 October 2019 17:44 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/5 "2019-10-26T17:44:33Z")

</div>

If you read the info panel for the `http request` node you will see that you can leave the URL field blank and can send the url in the message.

That way you can alter it in a function node or a template node

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [26 October 2019 18:52 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/6 "2019-10-26T18:52:14Z")

</div>

> [@easyE4](#):
>
> So my question is, how can I fill "setpoint" with the value from the silider.

Back home ...

Suppose you do it like this:

```auto
[{"id":"8511c41b.bbe858","type":"ui_slider","z":"dc82a538.a81ba8","name":"","label":"slider","tooltip":"","group":"abd602cc.8182d","order":0,"width":0,"height":0,"passthru":true,"outs":"end","topic":"","min":0,"max":"100","step":1,"x":1220,"y":260,"wires":[["34c47b36.d234c4","79cfefc0.806ef"]]},{"id":"79cfefc0.806ef","type":"http request","z":"dc82a538.a81ba8","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"https://postman-echo.com/get?var={{payload}}","tls":"","persist":false,"proxy":"","authType":"","x":1390,"y":260,"wires":[["a5f167ac.6b1ac8"]]},{"id":"a5f167ac.6b1ac8","type":"debug","z":"dc82a538.a81ba8","name":"Http request","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1560,"y":260,"wires":[]},{"id":"34c47b36.d234c4","type":"debug","z":"dc82a538.a81ba8","name":"Slider value","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1390,"y":320,"wires":[]},{"id":"abd602cc.8182d","type":"ui_group","z":"","name":"Default","tab":"92f88b13.45c2e8","disp":true,"width":"6","collapse":false},{"id":"92f88b13.45c2e8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/328e093182c311798b420ce2fb9739c5dfdeab62.png)

1. The slider generates values between 0 and 100, but not continiously (i.e. only on release) otherwise you will send too much http requests per second ...
2. The slider output message will contain the slider value inside the `msg.payload`
3. That message will trigger a http request. In the url we define that the value of `var` will be equal to the `msg.payload` of the input message (via a **Mustache** `{{payload}}` expression).
4. For this test I send a http request to the postman-echo site, which returns the original http request as http response. That way you can see the http request that you have been send!
5. The output message of the http-request node will contain the http response in the `msg.payload`. Since the postman-echo response is your original request, you can see that your url had been transformed to _[https://postman-echo.com/get?var=50](https://postman-echo.com/get?var=50)_

So this way you can put your slider value into your http request...

Short demo:

 ![slider_mutache](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b460da3d70199be0230cf9a946c10b148da1a6f8.gif)

Good luck with it!

---

<div class="post-metadata">

### Author: ![easyE4](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@easyE4](https://discourse.nodered.org/u/easyE4)
#### Post date: [26 October 2019 19:22 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/7 "2019-10-26T19:22:23Z")

</div>

Hi Bart,  
thank you so much that you take so much time to help me!  
I tried it with your suggestion. Unfortunately, my result looks a bit different and the variable is empty.

 ![node-red-flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/7ad9352b4ab6c60e12cfd1609e0aa41ded02e91e.jpeg)

Where is my mistake?  
Ralf

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [26 October 2019 19:41 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/8 "2019-10-26T19:41:05Z")

</div>

You are welcome. When I was a beginner, others where helping me too ...  
And those guys are still helping me now 😉

Suppose your url is  
[http://192.168.1.0.10/api/set/op=MW&index=1&val={{payload}](http://192.168.1.0.10/api/set/op=MW&index=1&val=%7B%7Bpayload%7D)}

The `{{payload}}` part of your URL will be replaced by the `msg.payload` of your input message. So if your slider is e.g. at value `13` I would expect your URL to become:  
[http://192.168.1.0.10/api/set/op=MW&index=1&val=13](http://192.168.1.0.10/api/set/op=MW&index=1&val=13)

But of course I have no idea what the response of that request will be.  
When you past the above URL in your browser, then you will see the result. As soon as that result is ok, I expect the http-request node to return exact the same response. But of course you need to make sure that the URL works also without Node-RED !!!

---

<div class="post-metadata">

### Author: ![easyE4](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@easyE4](https://discourse.nodered.org/u/easyE4)
#### Post date: [26 October 2019 20:43 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/9 "2019-10-26T20:43:07Z")

</div>

Hi Bart,  
if I use this request and trigger a timestamp,  
 ![Bild2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/10a1d610db6fd3abf92b3bd02e6763355e610607.jpeg)  
the word variable in my plc with the index 12 is set to the value 13.

 ![Bild1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/80cedc029b466b48e92e7c55b065e65b2a8ea881.jpeg)

Unfortunately, I find no way to change this value dynamically. I have been trying for hours now and can not find a solution.😟

---

<div class="post-metadata">

### Author: ![easyE4](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@easyE4](https://discourse.nodered.org/u/easyE4)
#### Post date: [26 October 2019 20:45 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/10 "2019-10-26T20:45:52Z")

</div>

I think it's time for a 🍺 😃

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [26 October 2019 20:59 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/11 "2019-10-26T20:59:39Z")

</div>

For you or for me ... 🤣  
Tomorrow - as soon as your hangover is gone - try the below flow.

```auto
[{"id":"28b18c7e.3ca1c4","type":"http request","z":"dc82a538.a81ba8","name":"","method":"GET","ret":"txt","paytoqs":false,"url":"http://192.168.0.10/api/set/op?op=MW&index={{index}}&val={{payload}}","tls":"","persist":false,"proxy":"","authType":"","x":1100,"y":80,"wires":[["d06e4425.047898"]]}]

```

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3301285331d357a0dd009b3bf2cc2a2eefef38bf.png)

If I understand correctly, your Node-RED flow should set two variables in your URL: index and value. Correct? So your input message needs to contain those two variables, and it is up to you where you store them. For example I have used `msg.index` and `msg.payload` (but instead of payload you could also have used e.g. `msg.value` ....). The payload is the slider value, but I don't know where you want to get the index. That is again up to you ...

Anyway my URL contains those two variables (as Mustache expressions), so it wel get those two variables from the input message.

Cheers !!!

---

<div class="post-metadata">

### Author: ![easyE4](https://avatars.discourse-cdn.com/v4/letter/e/a5b964/32.png) [@easyE4](https://discourse.nodered.org/u/easyE4)
#### Post date: [26 October 2019 21:24 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/12 "2019-10-26T21:24:51Z")

</div>

Hi Bart,  
It works 😀😀😀😀  
THANK YOU SO MUCH!! I am very, very grateful to you.

The next beer is on me 😉

Good night and a nice sunday  
Ralf

---

<div class="post-metadata">

### Author: ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)
#### Post date: [26 October 2019 21:32 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/13 "2019-10-26T21:32:48Z")

</div>

Glad to hear that it works. For the both of us ... 🤣  
Have a nice weekend!

---

<div class="post-metadata">

### Author: ![Twoink](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@Twoink](https://discourse.nodered.org/u/Twoink)
#### Post date: [30 August 2021 19:35 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/14 "2021-08-30T19:35:22Z")

</div>

@BartButenaers thanks for your info above. This was also helpful for me.

---

<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: [31 August 2021 06:18 UTC](https://discourse.nodered.org/t/send-value-in-a-http-request/17169/15 "2021-08-31T06:18:15Z")

</div>


