Totally new here query!

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? :slight_smile:


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:

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

You should then be able to configure the http request node url to:

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

Does this help you forward?

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"

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
In length: Data Structures: Objects and Arrays :: Eloquent JavaScript

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:


Importing and Exporting Flows

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

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

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

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.

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

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