# How to make a request to restart the flow (or node) using API?

**URL:** <https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959>\
**Category:** General\
**Created:** [26 June 2024 05:32 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959 "2024-06-26T05:32:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexeus](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@alexeus](https://discourse.nodered.org/u/alexeus)\
**Post date:** [26 June 2024 05:32 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/1 "2024-06-26T05:32:20Z")

</div>

There is a tuya-local-socket node in the flow that connects to the tuya lamp, but sometimes node loses connection and if i restart the flow (turn off and on the tuya node, deploy), it finds the lamp again. How to send a request to restart a node or flow using the API? I tried to compose a request to restart flow in a function node and send it via an http request node:  
msg.url = "[http://localhost:1880/flow/:id](http://localhost:1880/flow/:id)";  
msg.method = "PUT";  
msg.payload = {  
"id": "b2d3b44817b68364",  
"label": "Flow 1",  
"nodes": ,  
"configs":   
};  
return msg;

and receive a response in the console:  
"{"code":"not\_found","message":"Error"}"

Help me, please, how to make a request to restart the flow (or node)?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [26 June 2024 10:57 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/2 "2024-06-26T10:57:48Z")

</div>

It would be helpful it you provided the actual name of the tuya node you are using. A quick search of the flow library shows there are 11 nodes with 'tuya' in the name.

also the version of node-red and node.js (see the startup log)

---

<div class="post-metadata">

**Author:** ![alexeus](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@alexeus](https://discourse.nodered.org/u/alexeus)\
**Post date:** [26 June 2024 11:27 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/3 "2024-06-26T11:27:54Z")

</div>

node-red-contrib-tuya-auth 1.0.3 =\> tuya-local-socket  
Node-RED version 4.0.0  
nodejs version 20.15.0

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [26 June 2024 11:44 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/4 "2024-06-26T11:44:51Z")

</div>

You may want to read the about the [existing issues with that node](https://github.com/marsjupiter1/node-red-contrib-tuya-auth/issues).

Note: I don't own a tuya device so won't be of much help sorry.

---

<div class="post-metadata">

**Author:** ![alexeus](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@alexeus](https://discourse.nodered.org/u/alexeus)\
**Post date:** [26 June 2024 12:06 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/5 "2024-06-26T12:06:14Z")

</div>

According to the NR API description [[PUT /flow/:id : Node-RED](https://nodered.org/docs/api/admin/methods/put/flow/)], it is possible to update a individual flow configuration (restart?), regardless of which nodes exist in it. This is what I would like to do - restart flow by id.  
(tuya node does not have a reset command)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [26 June 2024 14:17 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/6 "2024-06-26T14:17:57Z")

</div>

Can you try changing :id to the actual id of that flow.

One way to get the id is to export that flow and look for the id in the export

---

<div class="post-metadata">

**Author:** ![alexeus](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@alexeus](https://discourse.nodered.org/u/alexeus)\
**Post date:** [26 June 2024 15:55 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/7 "2024-06-26T15:55:11Z")

</div>

I changed ":id" to the identifier of a specific flow. I run the PUT method:  
msg.url = "[http://localhost:1880/flow/b2d3b44817b68364](http://localhost:1880/flow/b2d3b44817b68364)";  
msg.method = "PUT";  
a pop-up window informs about changes to the stream on the server and offers to merge. If i select merge, all nodes are deleted from the flow. ☹

---

<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:** [26 June 2024 15:58 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/8 "2024-06-26T15:58:09Z")

</div>

> [@alexeus](#):
>
> e, all nodes are deleted from the flow

There is no api for restarting an individual flow.

The `PUT /flow/<id>` endpoint can be used to _update_ an existing flow - which will have the result of restarting it. But you have to provide the flow configuration as the body of the `PUT` request. If you don't send anything, then you are wiping it out and it will remove the nodes.

---

<div class="post-metadata">

**Author:** ![alexeus](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@alexeus](https://discourse.nodered.org/u/alexeus)\
**Post date:** [26 June 2024 18:33 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/9 "2024-06-26T18:33:16Z")

</div>

- Yes, that's how it works. First, I got the flow configuration (GET), wrote it to a variable (flow.set), then read it from the variable (flow.get), changed some value and sent an update (PUT). Flow reload, the nodes have been initialized again. Thank you.

---

<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:** [10 July 2024 18:34 UTC](https://discourse.nodered.org/t/how-to-make-a-request-to-restart-the-flow-or-node-using-api/88959/10 "2024-07-10T18:34:01Z")

</div>

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