# How to do multiple http get request for every 10 seconds without inject node

**URL:** <https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748>\
**Category:** General\
**Tags:** http-request\
**Created:** [15 August 2021 14:34 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748 "2021-08-15T14:34:17Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![cenbek53](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@cenbek53](https://discourse.nodered.org/u/cenbek53)\
**Post date:** [15 August 2021 14:34 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/1 "2021-08-15T14:34:17Z")

</div>

Hi there,

i am working on a project where i make a get request to a server which returns me the connection state of systems and machines as JSON. i use this return value to visualize the connection states in node red:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3bec64a6bf1f9dd6a70550dfc3131bb260a4aeec.png)

the next step is to query the status of each machine. for this i have an endpoint, which gives me this. in node-red i now want to make a query to this endpoint every 10 seconds to visualize the status, if the health is ok or not. the response will look like this:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/240462baa51bdc1e58e42ae01b20e3e23191b4d7.png)

for this i do NOT want to use an inject node, because i have to follow a certain rule regarding structure. this is to look like obove.

so i will modify the "mtconnect" and "opc ua" node like the http request node, only with the except that the nodes will make http request for every 10 seconds instead of only one time as the core node http request.

is there a way to implement a **modified version of the HTTP REQUEST NODE** that makes me a request every 10 seconds instead of just once?

thank you very much for the answers!!!

---

<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 August 2021 14:55 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/2 "2021-08-15T14:55:56Z")

</div>

Hi. Welcome to the forum.

Unless I am missing something, I can see no reason to modify the core node when what you are asking is 100% possible using either an inject node or a Cron type node.

Can you elaborate more?

---

<div class="post-metadata">

**Author:** ![cenbek53](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@cenbek53](https://discourse.nodered.org/u/cenbek53)\
**Post date:** [15 August 2021 15:00 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/3 "2021-08-15T15:00:28Z")

</div>

> [@Steve-Mcl](#):
>
> Cron

Firstly, thanks for answering!!  
So after visualization the configuration, we have a lot of machines and devices as nodes on Node-RED. So only this machines should be seen. It would be really messy if i would put a inject node for each of the machines, becuase they all have different endpoints to make a request.

---

<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 August 2021 15:06 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/4 "2021-08-15T15:06:40Z")

</div>

Yo don't need to use a preprogrammed inject per request. You can use change nodes to set-up the payload from any source, even an array populated dynamically if necessary.

---

<div class="post-metadata">

**Author:** ![cenbek53](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@cenbek53](https://discourse.nodered.org/u/cenbek53)\
**Post date:** [15 August 2021 15:06 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/5 "2021-08-15T15:06:54Z")

</div>

In general, i will make a request to the endpont, it will returns me a json string with all connection states of the machines. i will convert this json to a node red compatible json-string and will put this json to flows.json, where node-red reads the configuration of the flows. after rebooting the node red docker container, the page will refresh and we will see the connection state as shown above. now each of this "device" nodes should make a http request for a endpont, which will return ONLY the status of the device by id and not for the whole devices. and for this, i will turn the "device" to something like the http request node, only with the except that these will make a request to the specific endpont every 10 seconds.

---

<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 August 2021 15:09 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/6 "2021-08-15T15:09:55Z")

</div>

Still not clear I'm afraid.

Can you write the process as a flow chart or stepwise?

Perhaps something like...

1. Request a list of endpoints from http
2. Loop through each endpoint and generate a Payload,
3. Send this generated payload to the endpoint
4. Store the result in an object for later display on a dashboard

Etc

---

<div class="post-metadata">

**Author:** ![cenbek53](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@cenbek53](https://discourse.nodered.org/u/cenbek53)\
**Post date:** [15 August 2021 15:11 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/7 "2021-08-15T15:11:25Z")

</div>

i will describe you everything in detail, but needs a second for this!  
thanks a lot !!!

---

<div class="post-metadata">

**Author:** ![cenbek53](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@cenbek53](https://discourse.nodered.org/u/cenbek53)\
**Post date:** [15 August 2021 15:54 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/8 "2021-08-15T15:54:52Z")

</div>

imagine, that this flow will be created automatically, not important how its made:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/28eb5a6b6c616bbda68d6449205ef66b79f0a07c.png)  
the nodes you can see here (i will them call device-nodes) are created by me. but for now they are only dummies. that means, that these have no funcionality:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/d/3d9d8e283f0b63f03e805de33d59190b3e8c3e0d.png)

the idea is, to modify these device nodes, that they will make a http request to this endpoint:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/671679b2c3d6ad55633028a9201e3956198866c2.png). the id will represent the id of the node. so that each node will make a http request every 10 seconds. the response will look like this: ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/6428289a26a35a0aa1d7905bca2dfc06cc7e9792.png)

after receiving the JSON Object, the status object witihn the respone (see obove) should be processed. if the "health" and "state" key are "ok" and "running", then the node status should be green. if not it should be red like described in the docs:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/1/a1f75c7d48fb4466ed16ef97a02d8097e795560e.png)

for this i only want to modify the device nodes. i had the idea, to copy the source code of the "http request" node (the js and html file) and push it into the js and html file of the device node. in addition i will the feature, that the device nodes make a http request every 10 seconds automatically without using a switch node, inject node,....

now its hopely clear.

---

<div class="post-metadata">

**Author:** ![cenbek53](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@cenbek53](https://discourse.nodered.org/u/cenbek53)\
**Post date:** [19 August 2021 12:09 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/9 "2021-08-19T12:09:31Z")

</div>

are you still there ?  
😅

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [19 August 2021 15:43 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/10 "2021-08-19T15:43:59Z")

</div>

Sounds like you just want the first "node" in the flow to look like a single block, but have it do multiple things repeatedly... for that, you can use a [subflow](https://nodered.org/docs/developing-flows/flow-structure#making-reusable-flows).

In the parent flow, it looks like a single node, but when you edit the subflow, it can have many nodes inside it (e.g. `inject` -\> `http request` -\> `json`).

I would start by making a single flow that works as you expect, then select all the upstream nodes and use the Menu \> Subflows \> Selection to Subflow option to put them all into one displayed node.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [19 August 2021 15:57 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/11 "2021-08-19T15:57:43Z")

</div>

> [@cenbek53](#):
>
> It would be really messy if i would put a inject node for each of the machines, becuase they all have different endpoints to make a request.

Another nice feature of a subflow is that it can have environment vars that are used by the nodes running inside. For instance, the `http request` node in the subflow could use env string syntax to substitute the target url like this: `${DEVICE_URL}`

---

<div class="post-metadata">

**Author:** ![cenbek53](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@cenbek53](https://discourse.nodered.org/u/cenbek53)\
**Post date:** [19 August 2021 16:02 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/12 "2021-08-19T16:02:09Z")

</div>

Thanks a lot, its really good idea! Firstly i also had this idea but the feature with the env var are new for me. I will try it like you described. Thanks a lot again!!

---

<div class="post-metadata">

**Author:** ![cenbek53](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@cenbek53](https://discourse.nodered.org/u/cenbek53)\
**Post date:** [20 August 2021 19:32 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/13 "2021-08-20T19:32:32Z")

</div>

@shrickus is there a way to call the node\_id of the instance of the subflow within the subflow itself? i would set the http request URL like this: URL\_ENV\_VAR/node\_id

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [20 August 2021 19:42 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/14 "2021-08-20T19:42:40Z")

</div>

The `http request` node (and many others) can be configured with a blank url -- then, if the incoming `msg` contains a `url` field, it will be used in the http request. A good example of how to do it is in [this thread](https://discourse.nodered.org/t/injecting-messages-on-a-specific-node-for-building-approval-workflows/32640/12)

So I would suggest that your subflow includes a `change` node upstream of the http request node, which builds the target string and a sets it on the `msg.url` field. The only thing I'm not sure about is how to get the current subflow's id inside a `change` node... but if that's not available, just use another env var, maybe?

---

<div class="post-metadata">

**Author:** ![cenbek53](https://avatars.discourse-cdn.com/v4/letter/c/e9bcb4/32.png) [@cenbek53](https://discourse.nodered.org/u/cenbek53)\
**Post date:** [22 August 2021 20:02 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/15 "2021-08-22T20:02:40Z")

</div>

hey again, i did it!!  
thanks again for your help!! \<3

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/f/2f6b097fd1cd0fa30bee0db1a7148899ff4de877.png)

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [23 August 2021 15:37 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/16 "2021-08-23T15:37:47Z")

</div>

Looks good! I'm glad you got it all working.

For the benefit of the rest of us, could you show us a bit of how you set up the subflows? Specifically, how did you end up building the url from the env and id vars...

---

<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 September 2021 15:38 UTC](https://discourse.nodered.org/t/how-to-do-multiple-http-get-request-for-every-10-seconds-without-inject-node/49748/17 "2021-09-06T15:38:01Z")

</div>

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