Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Discuss
  3. User import / Batch user creation

User import / Batch user creation

Scheduled Pinned Locked Moved Discuss
apiuser management
7 Posts 4 Posters 947 Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    uwcrbc
    wrote on last edited by girish
    #1

    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,

    1 Reply Last reply
    1
    • girishG Offline
      girishG Offline
      girish
      Staff
      wrote on last edited by
      #2

      @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

      1 Reply Last reply
      0
      • BrutalBirdieB Offline
        BrutalBirdieB Offline
        BrutalBirdie
        Partner
        wrote on last edited by
        #3

        I also posted my script somewhere 🤔 let me dig it up

        Like my work? Consider donating a drink. Cheers!

        U 1 Reply Last reply
        0
        • BrutalBirdieB BrutalBirdie

          I also posted my script somewhere 🤔 let me dig it up

          U Offline
          U Offline
          uwcrbc
          wrote on last edited by
          #4

          @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

          1 Reply Last reply
          1
          • BrutalBirdieB Offline
            BrutalBirdieB Offline
            BrutalBirdie
            Partner
            wrote on last edited by BrutalBirdie
            #5

            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.

            Like my work? Consider donating a drink. Cheers!

            U necrevistonnezrN 2 Replies Last reply
            3
            • BrutalBirdieB BrutalBirdie

              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.

              U Offline
              U Offline
              uwcrbc
              wrote on last edited by
              #6

              @BrutalBirdie Thanks a lot!

              1 Reply Last reply
              0
              • BrutalBirdieB BrutalBirdie

                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.

                necrevistonnezrN Offline
                necrevistonnezrN Offline
                necrevistonnezr
                wrote on last edited by
                #7

                @BrutalBirdie That should be part of the docs!

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Bookmarks
                • Search