User import / Batch user creation
-
Hi,
Apologies in advance if I missed something here:
Up to not so long ago there was a possibility to import users in Cloudron (7.1 release notes make mention of it - There are also traces of it here and there in the forum. See here for example).
(User export seems to be missing too).
For the life of me, I cannot find this anywhere anymore. Thus I suspect it has been removed/disabled.
Is there any particular reasons for this?As an alternative, is there a known way to batch create users and generate invitation on the fly?
Many thanks,
-
@uwcrbc yes, this functionality was removed since it was not flexible in the way it was implemented.
You can script whatever your requirements are based on the API. The users API is now online at https://docs.cloudron.io/api.html#tag/Users
-
I also posted my script somewhere let me dig it up
-
@BrutalBirdie Oh that would be nice - thanks for this.
Thanks also @girish - This works for me also.
Just in passing:
- I initially had the same powershell annoyance as @prusaman here: https://forum.cloudron.io/post/62509 - Not sure what this is all about, but linux's just fine.
- the curl sample is missing an end quote here: https://docs.cloudron.io/api.html#tag/Users/operation/addUser
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $CLOUDRON_TOKEN" "https://$CLOUDRON_DOMAIN/api/v1/users" --data '{"username":"Example","email":"example@example.com","password":"insertYourPassword","displayName":"Example", "role":"user","fallbackEmail":"fallback@test.com"}
Thanks again
-
BrutalBirdie Partnerwrote on Apr 24, 2024, 11:17 AM last edited by BrutalBirdie Apr 24, 2024, 11:20 AM
Found it
Here is the python3 code:import json from pprint import pprint import requests # Each user to programmatically create must be in this JSON format data = [ { "Surname": "Lastname", "Name": "Firstname", "Login": "MyAwesomeLoginName", "Mail": "missing@null.none", "Password": "HahaClearTextPasswordGoBrrrrrr" } ] # Replace `DOMAIN.TLD` with your Domain url="https://my.DOMAIN.TLD/api/v1" # Replace `<PLACEHOLDER-TOKEN>` with your Cloudron Token headers = { "Content-Type": "application/json", "Authorization": "Bearer <PLACEHOLDER-TOKEN>" } for value in data: values= { "email": value["Mail"], "username": value["Login"], "password": value["Password"], "displayName": f'{value["Name"]} {value["Surname"]}', "role": "user", "fallbackEmail": value["Mail"], } data = json.dumps(values) try: pprint(data) createUser = requests.post(f'{url}/users', data=data, headers=headers) userId = createUser.json()["id"] pprint(userId) inviteUser = requests.post(f'{url}/users/{userId}/send_invite_email', data=json.dumps({"email": value["Mail"]}), headers=headers) if createUser.status_code != 201 or inviteUser.status_code != 202: print(f"Error creating user or inviting user") print(f"Create user status code: {createUser.status_code}") print(f"InviteUser user status code: {inviteUser.status_code}") exit() except Exception as e: pprint(e)
hope this helps.
ps: I added the invite user email to the program for you since I did not have it in there. -
@BrutalBirdie Thanks a lot!
-
@BrutalBirdie That should be part of the docs!
Post 5 of 7