You could use the Admin API to get the full flow configuration, modify it however you want, and then post it back.
https://nodered.org/docs/api/admin/methods/get/flows/
https://nodered.org/docs/api/admin/methods/post/flows/