Batch creation of users

I need to add 90 new users and allocate them to different projects. Is there any way to batch import (from a CSV or similar) multiple users?

Hi @Jims,

Unfortunately we haven’t any native tool in the platform to make this job, but you can use the Node-RED plugin to call’s REST API and create the user accounts automatically. The process would be the next:

First of all, we will need to know the aspect of the “new user account” API and it’s required parameters. The rest api can be found in the section “ Documentation - REST API” thanks to the Swagger tool it is very easy to learn how to use it and event perform little tests easily:

to this API we must add an authorization that we can create through’s access token manager, giving the token administration permissions. The complete API for my server would be something like this:

Using Node-RED we can create a flow with the next elements:

1- A CSV node to store the users data (email, enabled, password, role, user, verified)
2- The XXX node to create a JSON file with each line of the CSV
3- Using HTTP Request node, we can call’s REST API and send the JSON to create a user profile. Note that you have to configure it with bearer authorization:

I need to add an additional node (castin) to transform the boolean values from string to actual bool type as the API requires. But it works really nice, so i have exported the flow intro a json that you can use to import it in your node-RED using the Import option of the menu and complete the configuration with your server domain and token:

[{"id":"b0b74e2a.591ca","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"bffa7464.b5caa8","type":"inject","z":"b0b74e2a.591ca","name":"Inject","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":107,"y":56.00000190734863,"wires":[["9c36f3c1.41c46"]]},{"id":"fc9389e7.c0d4b8","type":"csv","z":"b0b74e2a.591ca","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":false,"include_null_values":false,"x":313.00000381469727,"y":155.00000381469727,"wires":[["c2afea47.3f77b8"]]},{"id":"80cbb987.c3ff58","type":"debug","z":"b0b74e2a.591ca","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":725.0000648498535,"y":308.0000057220459,"wires":[]},{"id":"9c36f3c1.41c46","type":"template","z":"b0b74e2a.591ca","name":"CSV data","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"email, enabled, password, role, user, verified\,true,\"123456_QWERTY\",\"user\",\"test\",true\,true,\"123456_QWERTY\",\"user\",\"test2\",true","output":"str","x":209.00002670288086,"y":112.00000190734863,"wires":[["fc9389e7.c0d4b8"]]},{"id":"c2afea47.3f77b8","type":"function","z":"b0b74e2a.591ca","name":"casting","func":"msg.payload.verified  = msg.payload.verified==='true';\nmsg.payload.enabled = msg.payload.enabled==='true';\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420.0001029968262,"y":212.00000381469727,"wires":[["d2da593c.acb638"]]},{"id":"d2da593c.acb638","type":"http request","z":"b0b74e2a.591ca","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","authType":"bearer","x":576.0001106262207,"y":263.8000297546387,"wires":[["80cbb987.c3ff58"]]}]

Using this system you can also create devices, projects and with a little of work even join all of them together.

Hope it helps!

1 Like

If I understand correctly this will require the Node_red plugin (which we don’t have access to)…