Configurations lost while creating a dynamic node and flow

I have started exploring, how to create a dynamic nodes in NodeRED and I found it was not possible, instead I can create a new flow dynamically with the nodeids mentioned below as suggested by the documentationo. I tested with below request with Bearer Token and Content-Type and it created a new flow and returned an object.

But the issue was as soon as below request executed successfully all my configurations got changed and Node-Red UI remains blank with no flow visible and running in the background, I have around 20-30 flows created and lost those.

Can someone help in restoring my configurations as earlier.

http://localhost:1880/flow
POST
{
"id": "91ad451.f6e52b8a",
"label": "loraapi",
"nodes": ["a2d5ec3d.d9992","b87a8378.e46a2","54c4b89d.82f088" ],
"configs":
}

Please find the attached image.

Thanks!

If you post a new flow to overwrite your old flow then that is exactly what you have done... overwritten your existing flow... We do keep a one level backup at this point as a file in your user directory usually called something like .flows_{hostname}.json.backup where {hostname} is the name of your computer. If you copy or rename that file back to flows_{hostname}.json you should be able to restart Node-RED back where you were.
If you have deployed (or posted) more than once then sadly that may have ben overwritten.

In addition to what @dceejay said have a look at the Projects feature which can save you a lot of trouble in situations like yours.

1 Like

Thanks for your suggestions, nothing worked for me, I think overwritten. Hopefully looking forward to have a better detailed documentation for NODE-RED to properly use the API calls

Sounds like the API calls worked just fine... Not sure that documentation would help much if you don't backup your flows... The few people I know who autogenerate flows do so outside of Node-RED - so they always deploy into a runtime only instance.

1 Like

I don't think you have deleted your flow configuration, but I do think you've corrupted it.

In your POST to the /flow endpoint, the example flow configuration you've shared is wrong:

"nodes": ["a2d5ec3d.d9992","b87a8378.e46a2","54c4b89d.82f088" ],

You have provided nodes as an array of strings. It should be an array of full node configurations.

I haven't tested what happens if you pass an array of strings rather than objects, but it may have appended those strings to your flow configuration and thus breaking it. This is why the editor looks completely blank.

At this point, manually edit your flow file. It should contain an array of node objects. Search for those strings you've added and remove them. Then restart NR.

If you're in doubt over what format to use, do a GET of /flow/<flow-id> for one of your existing flows and see what it looks like.

2 Likes

Thanks a lot, it worked!