# Totally new here query!

**URL:** <https://discourse.nodered.org/t/totally-new-here-query/27944>\
**Category:** General\
**Created:** [7 June 2020 15:18 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944 "2020-06-07T15:18:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheMaster](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@TheMaster](https://discourse.nodered.org/u/TheMaster)\
**Post date:** [7 June 2020 15:18 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/1 "2020-06-07T15:18:28Z")

</div>

Hi all apologies, I only started 'using' Node-Red a couple of days ago, I'm not bad with PowerShell but struggling with Node-Red a lot more.

I am trying to add a variable to a http API request for the dates below, so basically I want to pull in the last months data or maybe even just 1 day's data by using the same date in both dates, or just yesterday's date. When I added {{{env.get("date")}}}&startDate={{{env.get("date")}}} into the URL to replace the dates it didn't work, clearly got a lot of learning to do! Any ideas what I need to do apart from reading more!?

Basically I want to create dates as a variable and then add those variables into the date fields, thats it! sound simple,right? 🙂

[https://testsite/energy?timeUnit=DAY&endDate=2020-05-30&startDate=2020-05-01&staticdata](https://testsite/energy?timeUnit=DAY&endDate=2020-05-30&startDate=2020-05-01&staticdata)

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [7 June 2020 16:27 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/2 "2020-06-07T16:27:10Z")

</div>

Hi and welcome to the community!

What you would need to do is pass in the dates as the `msg` properties. Let's say toi pass in a message:

```auto
{
    "startDate": "2020-06-06", 
    "endDate": "2020-06-07"
} 

```

You should then be able to configure the http request node url to:  
`https://testsite/energy?timeUnit=DAY&endDate={{{endDate}}}&startDate={{{startDate}}}&staticdata`

This would mean start date is read from `msg.startDate` and the end date from `msg.endDate`.

Does this help you forward?

---

<div class="post-metadata">

**Author:** ![TheMaster](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@TheMaster](https://discourse.nodered.org/u/TheMaster)\
**Post date:** [7 June 2020 17:04 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/3 "2020-06-07T17:04:14Z")

</div>

Hi Ristomatti,

Thank you.

ok looks like the URL was not far off with the the Variables, however I think its the input I am struggling with to get a variable or in this case multiple variables into the URL

How do I declare these as variables ? or via a node?

{  
"startDate": "2020-06-06",  
"endDate": "2020-06-07"  
}

---

<div class="post-metadata">

**Author:** ![TheMaster](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@TheMaster](https://discourse.nodered.org/u/TheMaster)\
**Post date:** [7 June 2020 17:07 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/4 "2020-06-07T17:07:08Z")

</div>

Does this work like an array? So this is the payload and these are the properties of the array?

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [7 June 2020 17:48 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/5 "2020-06-07T17:48:25Z")

</div>

> [@TheMaster](#):
>
> Does this work like an array? So this is the payload and these are the properties of the array?

They are properties of an object. An object can store multiple named variables of any type. The message passed between nodes is always a message but the message can contain an array (or many). You can recognise an object from the curly braces `{}`. Array uses square brackets `[]`.

About objects and arrays: [Objects vs. Arrays - DEV Community](https://dev.to/zac_heisey/objects-vs-arrays-2g0e)  
In length: [Data Structures: Objects and Arrays :: Eloquent JavaScript](https://eloquentjavascript.net/04_data.html)

> [@TheMaster](#):
>
> How do I declare these as variables ? or via a node?

It can be done in multiple ways, like with a change or function node for example. It depends on your flow which method suits best. Here's a simple example with a change node you can import from the hamburger menu:

```auto
[{"id":"e37ecaa.92fae38","type":"debug","z":"49dde2ab.180f7c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":230,"y":220,"wires":[]},{"id":"28623e81.c1c602","type":"inject","z":"49dde2ab.180f7c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":100,"wires":[["518cb661.152878"]]},{"id":"518cb661.152878","type":"change","z":"49dde2ab.180f7c","name":"","rules":[{"t":"set","p":"startDate","pt":"msg","to":"2020-06-06","tot":"str"},{"t":"set","p":"endDate","pt":"msg","to":"2020-06-07","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":180,"y":160,"wires":[["e37ecaa.92fae38"]]}]

```

[Importing and Exporting Flows](https://nodered.org/docs/user-guide/editor/workspace/import-export)

---

<div class="post-metadata">

**Author:** ![TheMaster](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@TheMaster](https://discourse.nodered.org/u/TheMaster)\
**Post date:** [7 June 2020 17:57 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/6 "2020-06-07T17:57:59Z")

</div>

Ok great let me try them and come back to you, thanks for the help.

---

<div class="post-metadata">

**Author:** ![TheMaster](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@TheMaster](https://discourse.nodered.org/u/TheMaster)\
**Post date:** [7 June 2020 19:43 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/7 "2020-06-07T19:43:03Z")

</div>

Thanks, yep got that change node, no still same error server returns a JSON error but works with the dates.

BTW the site is a dummy site cant share the real site due to API keys

Here it is

```auto
[{"id":"d8ae9a2b.d1c158","type":"change","z":"a47938d9.e33ac8","name":"Name","rules":[{"t":"set","p":"startDate","pt":"msg","to":"2020-06-05","tot":"str"},{"t":"set","p":"endDate","pt":"msg","to":"2020-06-06","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":380,"wires":[["dbe964e.c6b6c98"]]},{"id":"b6a42295.96609","type":"inject","z":"a47938d9.e33ac8","name":"","topic":"Get","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":470.0142059326172,"y":376.00567626953125,"wires":[["d8ae9a2b.d1c158"]]},{"id":"9df09be8.563848","type":"ui_text","z":"a47938d9.e33ac8","group":"ff0165a2.2ac3a8","order":3,"width":"","height":"","name":"Yesterdays production 2","label":"Yesterdays production 2","format":"{{msg.payload.energy.values[0].value / 1000 | number : 3}} kWh","layout":"","x":1290,"y":380,"wires":[]},{"id":"dbe964e.c6b6c98","type":"http request","z":"a47938d9.e33ac8","name":"HTTPS","method":"GET","ret":"obj","paytoqs":false,"url":"https://testsite/site/energy?timeUnit=DAY&endDate={{{enddate}}}&startDate={{{startdate}}}&staticdata","tls":"","persist":false,"proxy":"","authType":"","x":940,"y":380,"wires":[["9df09be8.563848","9fdf1a1f.82e008"]]},{"id":"9fdf1a1f.82e008","type":"debug","z":"a47938d9.e33ac8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1210,"y":320,"wires":[]},{"id":"ff0165a2.2ac3a8","type":"ui_group","z":"","name":"Production Details","tab":"a359f4b0.2a6738","order":2,"disp":true,"width":"6","collapse":false},{"id":"a359f4b0.2a6738","type":"ui_tab","name":"Home","icon":"dashboard","order":"1"}]

```

---

<div class="post-metadata">

**Author:** ![ristomatti](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ristomatti/32/5857_2.png) [@ristomatti](https://discourse.nodered.org/u/ristomatti)\
**Post date:** [7 June 2020 20:20 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/8 "2020-06-07T20:20:29Z")

</div>

I'm not sure in what you still need help but I noticed from your flow there the dates are not correctly set in the http request node. You've got `startdate` and `enddate` instead of `startDate` and `endDate` in your url field. The variables are case sensitive.

---

<div class="post-metadata">

**Author:** ![TheMaster](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@TheMaster](https://discourse.nodered.org/u/TheMaster)\
**Post date:** [7 June 2020 20:46 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/9 "2020-06-07T20:46:54Z")

</div>

Damn lol yep it was a typo!

Thanks so much for that it's working!

Few more things to do, like how to get a month of data of date and value into a bar graph but that's for another day!

Thanks so much

---

<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:** [6 August 2020 20:50 UTC](https://discourse.nodered.org/t/totally-new-here-query/27944/10 "2020-08-06T20:50:23Z")

</div>

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