Hello
Please can somebody help with the working example of how to restart flows using API.
Link to Node Red documentation
I found a similar topic marked as solved, but I cannot really see the solution there.
I can use GET to retrieve the information about the flows and to get info about the specific flow.
I don't know how to structure and use this information to redeploy the flow.
My flows
[{"id":"38ebc8f0.806f88","type":"tab","label":"My Flow","disabled":false,"info":""},{"id":"10a7b362.152b9d","type":"inject","z":"38ebc8f0.806f88","name":"","topic":"Test","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":160,"wires":[["5dfc6842.05b878"]]},{"id":"5dfc6842.05b878","type":"change","z":"38ebc8f0.806f88","name":"","rules":[{"t":"set","p":"flowStatus","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":160,"wires":[["b34ba5fc.6d6518"]]},{"id":"b34ba5fc.6d6518","type":"http request","z":"38ebc8f0.806f88","name":"Get flows","method":"GET","ret":"obj","url":"http://localhost:1880/flows","tls":"","x":540,"y":160,"wires":[["95b8fef6.88cf7"]]},{"id":"95b8fef6.88cf7","type":"change","z":"38ebc8f0.806f88","name":"get flowId by name","rules":[{"t":"set","p":"flowId","pt":"msg","to":"*[type = 'tab' and label = $$.topic].id","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":750,"y":160,"wires":[["11379e70.7874d2"]]},{"id":"11379e70.7874d2","type":"http request","z":"38ebc8f0.806f88","name":"Get single flow","method":"GET","ret":"obj","url":"http://localhost:1880/flow/{{flowId}}","tls":"","x":960,"y":160,"wires":[["44b07581.39fe3c"]]},{"id":"44b07581.39fe3c","type":"debug","z":"38ebc8f0.806f88","name":"get single flow","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1140,"y":160,"wires":[]},{"id":"c16580ad.02c2d","type":"tab","label":"Test","disabled":false,"info":""},{"id":"7a75794c.af1c18","type":"inject","z":"c16580ad.02c2d","name":"","topic":"","payload":"","payloadType":"date","repeat":"5","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":240,"wires":[["591040.bf77cfc"]]},{"id":"591040.bf77cfc","type":"debug","z":"c16580ad.02c2d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":240,"wires":[]}]
EDIT 1.
I still don't know how to structure the json object and how to use it.
This is what I have for my header:
{
"Content-type": "application/json",
"Node-RED-Deployment-Type": "full",
"Node-RED-API-Version": "v2" //I'm not sure about this
}
where I should put this:
{
"rev": "abc-123", // I don't know what goes here
"flows": [
{
"type": "tab",
"id": "38ebc8f0.806f88c",
"label": "My Flow"
}
]
}
Finally how to post this to restart flow?
EDIT 2 - SOLUTION
Another day another attempt.
this is what's inside my function node
msg.url = 'http://localhost:1880/flows';
msg.method = 'POST';
msg.headers = {};
msg.headers['content-type'] = "application/json; charset=utf-8";
msg.headers['Node-RED-Deployment-Type'] = "reload";
msg.headers['Node-RED-API-Version'] = "v2";
msg.payload = {
"flows": [ { } ]
};
return msg;
test flow:
[{"id":"9755354.1a5d8c8","type":"tab","label":"Test"},{"id":"45b295b1.0045cc","type":"function","z":"9755354.1a5d8c8","name":"request","func":"msg.url = 'http://localhost:1880/flows';\nmsg.method = 'POST';\nmsg.headers = {};\nmsg.headers['content-type'] = \"application/json; charset=utf-8\";\nmsg.headers['Node-RED-Deployment-Type'] = \"reload\";\nmsg.headers['Node-RED-API-Version'] = \"v2\";\nmsg.payload = {\n \"flows\": [\n {\n \"type\": \"tab\",\n \"id\": \"9755354.1a5d8c8\",\n \"label\": \"Test\"\n }\n ]\n};\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":60,"wires":[["cd0b9552.5f3be8"]]},{"id":"2a590784.f7a868","type":"debug","z":"9755354.1a5d8c8","name":"results","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":610,"y":60,"wires":[]},{"id":"38dbceb9.0b5482","type":"inject","z":"9755354.1a5d8c8","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":60,"wires":[["45b295b1.0045cc"]]},{"id":"cd0b9552.5f3be8","type":"http request","z":"9755354.1a5d8c8","name":"","method":"use","ret":"txt","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":450,"y":60,"wires":[["2a590784.f7a868"]]},{"id":"4fd571c0.a666f","type":"inject","z":"9755354.1a5d8c8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"1","x":170,"y":140,"wires":[["f1187019.7b86b"]]},{"id":"f1187019.7b86b","type":"debug","z":"9755354.1a5d8c8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":420,"y":140,"wires":[]}]
After triggering the request Test flow is reloaded and restarted and the timestamp will appear in the debug window 1 second later.