# Variable in HTTP URL

**URL:** <https://discourse.nodered.org/t/variable-in-http-url/58468>\
**Category:** General\
**Created:** [16 February 2022 13:52 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468 "2022-02-16T13:52:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/olivia/32/57161_2.png) [@Olivia](https://discourse.nodered.org/u/Olivia)\
**Post date:** [16 February 2022 13:52 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468/1 "2022-02-16T13:52:05Z")

</div>

Hello everyone,

I am trying to change my URL from the HTTP node with some variables.  
The range depends on the last two numbers in the URL. I would like to get those values from the date node.  
can someone help me please?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/7/97adfcf77d3958821f870fefc9944a3518b69e71.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39bfc4559d456c3700e28c06476aaed35a7f71ef.png)[

```auto
[{"id":"ced92f11b1ac93e9","type":"ui_date_picker","z":"27cc266ed6fe3207","name":"","label":"Begin datum","group":"772b1b396b59caed","order":1,"width":3,"height":"2","passthru":true,"topic":"topic","topicType":"msg","className":"","x":330,"y":1660,"wires":[["e995284cc644bb76"]]},{"id":"3323423a7ba7bba7","type":"ui_date_picker","z":"27cc266ed6fe3207","name":"","label":"Eind datum","group":"772b1b396b59caed","order":2,"width":3,"height":"2","passthru":true,"topic":"topic","topicType":"msg","className":"","x":330,"y":1700,"wires":[["a007fd8b9c6748ed"]]},{"id":"4bb69eaed3164003","type":"debug","z":"27cc266ed6fe3207","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":1660,"wires":[]},{"id":"e995284cc644bb76","type":"function","z":"27cc266ed6fe3207","name":"","func":"//Waarden toekennen\n\nvar BeginDatum = msg.payload\n\n\n//Weergeven in console\nmsg.payload.BeginDatum = BeginDatum\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":1660,"wires":[["4bb69eaed3164003","03514bb389890642"]]},{"id":"ab4e93d77159a4df","type":"inject","z":"27cc266ed6fe3207","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":160,"y":1680,"wires":[["ced92f11b1ac93e9","3323423a7ba7bba7"]]},{"id":"a007fd8b9c6748ed","type":"function","z":"27cc266ed6fe3207","name":"","func":"//Waarden toekennen\nvar EindDatum = msg.payload\n\n\n//Weergeven in console\nmsg.payload.EindDatum = EindDatum\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":1700,"wires":[["4bb69eaed3164003","03514bb389890642"]]},{"id":"03514bb389890642","type":"http request","z":"27cc266ed6fe3207","name":"Laadpaal uitlezen","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://app1pub.smappee.net/dev/v3/chargingparks/59796/sessions?range=1640991600000,1643669940000","tls":"","persist":false,"proxy":"","authType":"bearer","senderr":false,"credentials":{},"x":750,"y":1760,"wires":[["f905ccdb55bd2d80"]]},{"id":"f905ccdb55bd2d80","type":"debug","z":"27cc266ed6fe3207","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":950,"y":1760,"wires":[]},{"id":"772b1b396b59caed","type":"ui_group","name":"Selecteer onderstaande data","tab":"e6a0e46d81483439","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"e6a0e46d81483439","type":"ui_tab","name":"Laadpalen","icon":"dashboard","order":9,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![lorccan](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@lorccan](https://discourse.nodered.org/u/lorccan)\
**Post date:** [16 February 2022 14:03 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468/2 "2022-02-16T14:03:14Z")

</div>

You can construct the URL outside the http request node and pass it in as msg.url

(You leave the URL in the HTTP request node blank.)

---

<div class="post-metadata">

**Author:** ![Olivia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/olivia/32/57161_2.png) [@Olivia](https://discourse.nodered.org/u/Olivia)\
**Post date:** [16 February 2022 14:18 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468/3 "2022-02-16T14:18:43Z")

</div>

Thanks for responding.

I made the url outside of the http node but it still doenst work. do you see what I did wrong?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/78a825c05db1257c7f900924000787331a88d0f7.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c424fa3db19d6d8c57f0e07c79a2d5a2aee996c.png)

Thanks in advance  
Olivia

---

<div class="post-metadata">

**Author:** ![lorccan](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@lorccan](https://discourse.nodered.org/u/lorccan)\
**Post date:** [16 February 2022 14:21 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468/4 "2022-02-16T14:21:45Z")

</div>

Did you leave the URL in the http node empty?

---

<div class="post-metadata">

**Author:** ![Olivia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/olivia/32/57161_2.png) [@Olivia](https://discourse.nodered.org/u/Olivia)\
**Post date:** [16 February 2022 14:22 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468/5 "2022-02-16T14:22:27Z")

</div>

i did leave it empty

---

<div class="post-metadata">

**Author:** ![lorccan](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@lorccan](https://discourse.nodered.org/u/lorccan)\
**Post date:** [16 February 2022 14:23 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468/6 "2022-02-16T14:23:37Z")

</div>

I would start by putting a debug node on the output of the node that sets the URL. It's most likely a concatenation issue. (I am not an expert, so I might be wildly wrong!)

EDIT: Just a thought: perhaps start by setting your url to the literal string you showed in your first post. That way you will know whether the value is being accepted.

---

<div class="post-metadata">

**Author:** ![Olivia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/olivia/32/57161_2.png) [@Olivia](https://discourse.nodered.org/u/Olivia)\
**Post date:** [16 February 2022 14:32 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468/7 "2022-02-16T14:32:18Z")

</div>

Hi  
When i put the normal url in the function node, it works

when i put the new url in the function node I get errors  
this is how the new url looks

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [16 February 2022 14:34 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468/8 "2022-02-16T14:34:32Z")

</div>

You would need to join the function messages, then you can use template or other means to construct the url  
e,g.

```auto
[{"id":"ab4e93d77159a4df","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":640,"wires":[["ced92f11b1ac93e9","3323423a7ba7bba7"]]},{"id":"ced92f11b1ac93e9","type":"ui_date_picker","z":"bf9e1e33.030598","name":"","label":"Begin datum","group":"772b1b396b59caed","order":1,"width":3,"height":"2","passthru":true,"topic":"begin","topicType":"str","className":"","x":240,"y":540,"wires":[["159c59fe.cc5886"]]},{"id":"3323423a7ba7bba7","type":"ui_date_picker","z":"bf9e1e33.030598","name":"","label":"Eind datum","group":"772b1b396b59caed","order":2,"width":3,"height":"2","passthru":true,"topic":"eind","topicType":"str","className":"","x":240,"y":580,"wires":[["159c59fe.cc5886"]]},{"id":"159c59fe.cc5886","type":"join","z":"bf9e1e33.030598","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":630,"y":560,"wires":[["4bb69eaed3164003","f3e6e4ec.a9fe5"]]},{"id":"4bb69eaed3164003","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":540,"wires":[]},{"id":"f3e6e4ec.a9fe5","type":"template","z":"bf9e1e33.030598","name":"","field":"url","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"https://app1pub.smappee.net/dev/v3/chargingparks/59796/sessions?range={{payload.begin}},{{payload.eind}}","output":"str","x":780,"y":600,"wires":[["f905ccdb55bd2d80","03514bb389890642"]]},{"id":"03514bb389890642","type":"http request","z":"bf9e1e33.030598","name":"Laadpaal uitlezen","method":"GET","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"bearer","x":660,"y":640,"wires":[["4bb69eaed3164003"]]},{"id":"f905ccdb55bd2d80","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"url","targetType":"msg","statusVal":"","statusType":"auto","x":980,"y":600,"wires":[]},{"id":"772b1b396b59caed","type":"ui_group","name":"Selecteer onderstaande data","tab":"e6a0e46d81483439","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"e6a0e46d81483439","type":"ui_tab","name":"Laadpalen","icon":"dashboard","order":9,"disabled":false,"hidden":false}]

```

[edit] infact the function nodes are not needed at all

---

<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:** [2 March 2022 14:34 UTC](https://discourse.nodered.org/t/variable-in-http-url/58468/9 "2022-03-02T14:34:48Z")

</div>

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