Batch adding users (e.g. from list file)

Hello!

I think it would be great to be able to batch add users (in groups) from list files.

My use case is that I would like to add my students (groups for different classes) such that I can easily share files with them. But I would rather not have to manually add 200 students per year. Instead, I could think of an import function that reads in data from a csv file (name, user name, initial password, group) to automatically create users from within nextcloud.

I have found suggestions of doing that on the console with occ. But I don’t seem to be able to do that on my webhosting account. So a native solution would be great.

What do you think? I hope this can be done.

Just humbly wondering:
Is this taken into account or merely ignored without comment?

There is an API that can be used to create users. There is for example a small python library that can be used to add users:

Thanks for the hint! I will look into it.

Nonetheless, I think it would still be great to be able to do it inside NC.

You can also use the Nextcloud command line interface to create users: ./occ user:add <uid>. A small batch file would do the rest :wink:

I wrote a small script for batch-adding users from a CSV file, based on that library.
I’ll open-source it some time.

1 Like

Hi, I made a Python CLI tool for that: https://github.com/t-markmann/nc-userimporter
Just posted here as well: Import Many Users

Just paste your data correctly into the users.csv and config.xml and execute the program.
This tool is executed locally and uses the Nextcloud API on your instance.

It’s not a beauty, but it does the job :slightly_smiling_face:

1 Like

Do you know if this will work with a “snap” install of Nextcloud? I’m getting the following error:

HTTPSConnectionPool(host=‘example.com’, port=443): Max retries exceeded with url: /ocs/v1.php/cloud/users (Caused by NewConnectionError(’<urllib3.connection.VerifiedHTTPSConnection object at 0x0000020B989262E8>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it’))
The CURL request could not be performed.

I did not try it with a snap install, but since it uses the NC API, it should work.

Do you use a self signed certificate?
Or a plain HTTP connection?
It will only work with HTTPS connections on port 443 i guess. And I did not try it with a self signed cert :smirk:

Seeing the WinError: do you have a linux machine running somewhere? Maybe as virtual machine? You could try on linux, maybe some windows-voodoo is blocking something…

Thanks for the response - I needed to convert to https, and it now works, thank you.

Great, happy to help :slightly_smiling_face:

Hello,

and thanks, how can I run this script? Do I need really the python environment for, what is the correct usage.

My nextcloud version is 17.0.1 running on 18.0.4 LTS

Maaaany thanks

Haydar

Hi!
No, you don’t need to install python. It is included in the packages in “build”: https://github.com/t-markmann/nc-userimporter/tree/master/build

Follow the instructions here: https://github.com/t-markmann/nc-userimporter#instructions

If it doesn’t work just send me a message. There are some bugs I will fix in the next days and make a new build :slightly_smiling_face:

Cool, it worked for me now! But I have to provide passwords, otherwise I get this error:

Traceback (most recent call last):
File “nc-userimporter.py”, line 94, in
IndexError: string index out of range
[31114] Failed to execute script nc-userimporter