# How to start the execution of functionality in node red using the api?

**URL:** https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855
**Category:** General
**Created:** [17 August 2021 20:01 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855 "2021-08-17T20:01:41Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![Snoz3f](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Snoz3f](https://discourse.nodered.org/u/Snoz3f)
#### Post date: [17 August 2021 20:01 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/1 "2021-08-17T20:01:41Z")

</div>

Hello. How can i start execution in node red from another app with node-red api? RED.nodes.startFlow?

---

<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: [17 August 2021 21:22 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/2 "2021-08-17T21:22:36Z")

</div>

Flows in the runtime can be triggered by many events.

You can start a flow by (including but not limited to) an http endpoint, a TCP in, an MQTT in node, a telegram message, a physical input.

What are you actually trying to achieve?

---

<div class="post-metadata">

### Author: ![Snoz3f](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Snoz3f](https://discourse.nodered.org/u/Snoz3f)
#### Post date: [17 August 2021 21:37 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/3 "2021-08-17T21:37:05Z")

</div>

I have implemented the creation functionality flow functionality but I need the generated flow to start performing its internal functionality after creation

---

<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: [17 August 2021 21:46 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/4 "2021-08-17T21:46:47Z")

</div>

> [@Snoz3f](#):
>
> I have implemented the creation functionality flow functionality

What does this mean? Did you create a flow externally to node-red and post it via a the admin endpoints? Or did you use the node-red editor to create your flow?

And, since a flow is event based (i.e. sending a `msg` through the wires) it works by sending a msg into it, what do you mean exactly by "start execution"? trigger it once? trigger it repeatedly?

---

<div class="post-metadata">

### Author: ![Snoz3f](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Snoz3f](https://discourse.nodered.org/u/Snoz3f)
#### Post date: [17 August 2021 22:25 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/5 "2021-08-17T22:25:01Z")

</div>

Look, I have a functional that creates the same type of flows with help RED.nodes.addFlow(), they have a certain logic. And I need this logic to be executed after creating flow

---

<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: [17 August 2021 22:35 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/6 "2021-08-17T22:35:51Z")

</div>

It would have been useful to include that information in the first place.

As I don't know what that function does I can only suggest you try building your flow with an inject set to trigger on start up - see if that works.

As I said in a previous post, flows are always executing in the runtime, waiting for a msg to trigger them.

Apart from that, I can't help further.

---

<div class="post-metadata">

### Author: ![Snoz3f](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Snoz3f](https://discourse.nodered.org/u/Snoz3f)
#### Post date: [17 August 2021 22:49 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/7 "2021-08-17T22:49:41Z")

</div>

Basically all I need is to run inject and that's it all

---

<div class="post-metadata">

### Author: ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)
#### Post date: [17 August 2021 23:00 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/8 "2021-08-17T23:00:00Z")

</div>

Presumably once you load your flows then you will do a reload of NR to enable them

If you have as the first node an inject node that is set to inject once on startup then it will send whatever (by default timestamp) you have configured it for to get your node going.

I can not believe if you have created a flow programatically you need to ask a question at this level (and quite rudely too)

Craig

---

<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: [17 August 2021 23:09 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/9 "2021-08-17T23:09:25Z")

</div>

> [@Snoz3f](#):
>
> Basically all I need is to run inject

If that had been your first question, I would have told you the inject nodes have a http endpoint that you can call to operate it. That's how the inject button works in the node-red editor. Take a look at the inject html src code in the node-red repo for how it does it then replicate that functionality in your express application.

---

<div class="post-metadata">

### Author: ![Snoz3f](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Snoz3f](https://discourse.nodered.org/u/Snoz3f)
#### Post date: [17 August 2021 23:10 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/10 "2021-08-17T23:10:46Z")

</div>

Its not difficult api has method `RED.nodes.addFlow(flow)`

---

<div class="post-metadata">

### Author: ![Snoz3f](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Snoz3f](https://discourse.nodered.org/u/Snoz3f)
#### Post date: [17 August 2021 23:11 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/11 "2021-08-17T23:11:58Z")

</div>

That is, in general, it is possible to implement it?

---

<div class="post-metadata">

### Author: ![paulkeates](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@paulkeates](https://discourse.nodered.org/u/paulkeates)
#### Post date: [18 August 2021 14:45 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/12 "2021-08-18T14:45:35Z")

</div>

Deleting based on feedback...

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [18 August 2021 14:48 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/13 "2021-08-18T14:48:41Z")

</div>

Hi @paulkeates - I'm not sure that response is warranted.

@Snoz3f - can you explain a bit more about what you are doing? If you have a flow that is started by an Inject node, then there will be an HTTP Admin endpoint you could use to trigger it. If you use devtools in the browser when manually triggering an inject node, you'll see how it works.

But it would probably be better to use another node type here - such as an HTTP In node so you can completely control the end point used to trigger your flow.

---

<div class="post-metadata">

### Author: ![Snoz3f](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Snoz3f](https://discourse.nodered.org/u/Snoz3f)
#### Post date: [18 August 2021 19:03 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/14 "2021-08-18T19:03:31Z")

</div>

Let me explain in order what I want to achieve. I have a generator of the same type of flow, it is located on the express server. It all perform the same logic with different data, then it save the result in mongo. The only thing I need to achieve is that after generating flow, it starts and executes its logic.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [18 August 2021 19:25 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/15 "2021-08-18T19:25:41Z")

</div>

A flow is "started" as soon as it gets deployed in the runtime. This is what the `addFlow` API you've asked about is doing.

So I'm not sure what else you are asking, without more information about the flow you are adding and what node it begins with.

---

<div class="post-metadata">

### Author: ![Snoz3f](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Snoz3f](https://discourse.nodered.org/u/Snoz3f)
#### Post date: [18 August 2021 19:42 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/16 "2021-08-18T19:42:40Z")

</div>

It starts with the timestamp node. Look my whole goal is to run timestamp from the code. The whole stream is just a regular html parser. It makes a request and receives all the data that it has collected. And then mongo saves them.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [18 August 2021 20:00 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/17 "2021-08-18T20:00:24Z")

</div>

> [@Snoz3f](#):
>
> the timestamp node.

I don't know what node that is. Can you be more specific? Or maybe share a screenshot of a flow.

But still I'm not clear what your question is. If you want to trigger a flow from outside of Node-RED, then pick a node that exposes itself in some way you can call it. Such as an http end point, or tcp listener, or mqtt subscriber.

---

<div class="post-metadata">

### Author: ![paulkeates](https://avatars.discourse-cdn.com/v4/letter/p/9de053/32.png) [@paulkeates](https://discourse.nodered.org/u/paulkeates)
#### Post date: [18 August 2021 20:55 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/18 "2021-08-18T20:55:18Z")

</div>

Hi,

Diplomatically: I believe the 'timestamp node' is the inject node.

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

It dynamically changes the label to 'timestamp' once it is placed on the flow.

They may be asking how can they 'loop' or restart the processing in order to iterate against the endpoint and 'scrape' the data & save it to Mongo... ?

Something like an inject followed by repeat:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/1/819c301ffd57dac32fad143ffe2a31176c8e145a.png)

Cheers,

Paul

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [18 August 2021 21:02 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/19 "2021-08-18T21:02:54Z")

</div>

> [@paulkeates](#):
>
> Diplomatically: I believe the 'timestamp node' is the inject node.

Indeed, that is likely. But I was hoping to get @Snoz3f to confirm that so we can at least start from a common point of terminology - the Inject node.

But any thing is just speculation and guesses that may, or may not, help move the discussion forward. What we really need are actual details from @Snoz3f.

---

<div class="post-metadata">

### Author: ![Snoz3f](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@Snoz3f](https://discourse.nodered.org/u/Snoz3f)
#### Post date: [19 August 2021 08:36 UTC](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855/20 "2021-08-19T08:36:37Z")

</div>

Yes its inject. For some reason, the node sometimes changes its name.

[Next page](https://discourse.nodered.org/t/how-to-start-the-execution-of-functionality-in-node-red-using-the-api/49855.md?page=2)
