# How to generate unique node ID when creating a flow via node-red API

**URL:** https://discourse.nodered.org/t/how-to-generate-unique-node-id-when-creating-a-flow-via-node-red-api/18237
**Category:** General
**Created:** [21 November 2019 13:30 UTC](https://discourse.nodered.org/t/how-to-generate-unique-node-id-when-creating-a-flow-via-node-red-api/18237 "2019-11-21T13:30:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Charlotte](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@Charlotte](https://discourse.nodered.org/u/Charlotte)
#### Post date: [21 November 2019 13:30 UTC](https://discourse.nodered.org/t/how-to-generate-unique-node-id-when-creating-a-flow-via-node-red-api/18237/1 "2019-11-21T13:30:05Z")

</div>

Hello,

I would like to create a flow by using nodered API with this guide [https://nodered.org/docs/api/admin/methods/post/flow/](https://nodered.org/docs/api/admin/methods/post/flow/)

Actually my plan is to copy paste an existing flow with only few modifications (serial request properties + global variable properties). This is to allow the user of the app to connect several serial devices of the same brand and model.

However I need to generate unique ids for the nodes included in this new flow.

Is there a way to ask nodered to generate a unique node id ?  
Or should I generate a random id and parse all the flows to be sure it's not already used ?  
Is there no risk that node-red use this randomly generated id in the future ?

Thanks for your help

---

<div class="post-metadata">

### Author: ![POne](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@POne](https://discourse.nodered.org/u/POne)
#### Post date: [14 May 2020 14:30 UTC](https://discourse.nodered.org/t/how-to-generate-unique-node-id-when-creating-a-flow-via-node-red-api/18237/2 "2020-05-14T14:30:38Z")

</div>

Hi Charlotte, I had the same problem as you. I have found that IDs are generated with this JScript function **(1 + Math.random () \* 4294967295) .toString (16);**

You can find it on file @node-red/util/lib/util.js, function generateId()

I hope it is useful for you  
Ciao

---

<div class="post-metadata">

### Author: ![Charlotte](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@Charlotte](https://discourse.nodered.org/u/Charlotte)
#### Post date: [30 September 2020 12:46 UTC](https://discourse.nodered.org/t/how-to-generate-unique-node-id-when-creating-a-flow-via-node-red-api/18237/3 "2020-09-30T12:46:50Z")

</div>

Hi,  
Thanks.  
Finally I used uuid JS library.  
I found we can use JS library by adding them in settings.js file

---

<div class="post-metadata">

### Author: ![xjust](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/xjust/32/39096_2.png) [@xjust](https://discourse.nodered.org/u/xjust)
#### Post date: [27 October 2021 10:12 UTC](https://discourse.nodered.org/t/how-to-generate-unique-node-id-when-creating-a-flow-via-node-red-api/18237/4 "2021-10-27T10:12:25Z")

</div>

can you teach me how did you do this ?  
im interested in the same thing 🙂 also there is ui involved, generate new ui groups/subgroups.

many thanks
