Mass user import

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can. :heart:

The Basics

  • Nextcloud Server version (e.g., 29.x.x): AIO 32.0.4
  • Operating system and version (e.g., Ubuntu 24.04): Debian 12
  • Web server and version (e.g, Apache 2.4.25): ?
  • Reverse proxy and version _(e.g. nginx 1.27.2): n/a
  • PHP version (e.g, 8.3): 8.3.29
  • Is this the first time you’ve seen this error? (Yes / No): yes
  • When did this problem seem to first start? first try
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.): AIO
  • Are you using CloudfIare, mod_security, or similar? (Yes / No): No

Summary of the issue you are facing:

I’m looking for a method to import a batch of users and tried to use the nc-userimporter script, as it worked fine for me with a previous instance on NC.

However, I stumbled upon many issues and I’m not sure I still can use the script with the most recent releases:

  • The script documentation stipulates that I need to install all required dependencies first, so I started a shell into the nextcloud-aio-nextcloud container and tried to install those dependencies.
  • The command `python -m pip install --user requests` is rejected as Python says there’s “No module named pip”.
  • I then tried to install pip but the command `python -m ensurepip --upgrade` returns an error “error: externally-managed-environment”.
  • I finally tried to run the script without any dependency (`python3 nc-userimporter.py`) and… it obviously fails because of the missing dependencies! :man_shrugging:

Hence the point above: I don’t really know if nc-userimporter is still valid with AIO 32.0.4. If not, is there any alternative? I don’t want to create 250+ users manually…

Thanks in advance for any help!

From the looks of it nc-userimporter uses the Nextcloud Provisioning API. So it doesn’t benefit at all from being on the server itself.

Just install it on a workstation or whatever that has connectivity to the Nextcloud instance.

did you try occ ? it’s easy to create a user and also script it occ user:.. manual

Thanks @jtr ! So you mean I could install nc_userimporter e.g. on the host machine? But how would the script communicate with the Nextcloud container? :thinking:

Thanks @wwe ! Yes, I know I could create a user using the occ command, but I’m not a developer and can’t create a bash script that reads the CSV file, parse each line and call occ, event if it would actually be the safest way to perform a mass import. :man_shrugging:

Yes, nc-userimporter is still a valid option on AIO 32. You should run it on your host/workstation (or any machine that can reach your Nextcloud URL), not inside the Nextcloud container. It talks to Nextcloud via HTTPS Provisioning API, so no direct container access is needed. The pip/ensurepip errors you saw are from the container’s managed Python environment. Try it externally first; if it still fails, share the exact error/output and we can narrow it down step by step.

according to the old Perl motto TIMTOWTDI - there is more than one way to do it - scriptng the command is maybe the first way you think about but others exist.

If the task is not repeating but like one-time thing you can simply craft multiple occ commands using Calc/Excel e.g.

user name command
bob Bob =concat("occ user:add ";A2;B2)
alice Alice =concat("occ user:add ";A3;B3)

Thanks for the clarification! It actually launched from the host, after the dependencies were installed.

I tried first with one user only and got the following error message:

Traceback (most recent call last):
File “/root/Applications/NC-UserImporter/nc-user_manager.py”, line 266, in 
main_menu(config, nc_api, user_manager)
File “/root/Applications/NC-UserImporter/nc-user_manager.py”, line 248, in main_menu
import_users(config, nc_api)
File “/root/Applications/NC-UserImporter/nc-user_manager.py”, line 200, in import_users
row[‘username’] = html.escape(row[‘username’]).translate(MAPPING)
KeyError: ‘username’

The first line of the CSV file is however compliant with the template provided:

username;displayname;password;email;groups;subadmin;quota

Could there be some encoding issue (the CSV file has been created on a Win11 machine, UTF-8 encoded)?

1 Like

What is the expected encoding with the script?