Admin API flow creation with duplicate IDs


When creating flows via the POST method on the Admin API (POST /flow), if the flow has a node with an ID already in use, the method will fail. As the docs state:

All of the nodes in the flow must have unique id properties. The request will rejected if any of the id s are already in use.

However, when importing a flow via the GUI and using the clipboard import, an option to generate IDs is proposed to the user:

Some of the nodes you are importing already exist in your workspace.
Select which nodes to import and whether to replace the existing nodes, or to import a copy of them.

That's implemented via the importOptions.generateIds configuration in the clipboard.js file.

Proposal: Would it be possible to add an option (for example in the headers) to generate IDs if duplicates are found?

As a workaround you may find this post interesting

Also the link to the Node-red util file with the code that generates the ids. (LINK)
You may implement the same method to give the nodes a unique id before the POST ?

Why would you want to POST a flow with duplicate node ids which in my mind means a duplicate flow ?!
Maybe you should be using PUT /flow/:id that updates a Flow ?

Hi @UnborN,

Yeah, I've seen that workaround and it's an option, but I think that it'd be great to also be able to create IDs automatically like when using the Web UI.

Regarding the why, imagine a Flow where I am reading data from an endpoint and applying some logic to it. Then, the same flow is going to be used for 5 different endpoints. In this scenario, a template flow can be used where only the endpoint has to be changed and the IDs are already defined. When using the POST, one could create the 5 flows without dealing with with duplicate IDs externally.

Hope that makes sense.

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