Announcement

Collapse
No announcement yet.

Create New User through API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Create New User through API

    HI there,

    I have read all the documentation and still struggling on how to create a new user using only API calls.
    I know that I need to PUT data into the users table, but there is no permission in the role editor for me to give 'Users Create' to my API user.

    Any thoughts? Thanks heaps.

  • #2
    I have had success by creating an admin user with just create access.
    Is this the best way to achieve this?

    Comment


    • #3
      If you want to create user you have to use POST, not PUT. You have to create new role for API user and in this user allow for Users creation.
      Then create new API user and assign role to this user https://i.imgur.com/8r9lLVj.png

      Comment


      • #4
        Thanks.

        Comment


        • #5
          I also dealt with api users a little earlier. In any case, I created a separate role for the api user and activated "Webhooks". and of course users...

          Comment


          • #6
            Originally posted by MrThiemann View Post
            I also dealt with api users a little earlier. In any case, I created a separate role for the api user and activated "Webhooks". and of course users...
            Imho there is no need to activate webhooks in this case

            Comment


            • #7
              Hi guys, did you manage to successfully create a user via an API call? I'm not that great at PHP and JSON but it looks like the structure of EspoCRM has changed a lot in v7 onwards (I'm running 7.0.9), so i think some of the steps in the older posts on this forum no longer work for this. I've followed the steps to modify the User.json in Scope to give me access to assign Create permissions for User in role I can then assign to an API user, and I know the API user is good as I can successfully execute a GET to return users. However whenever I try a POST to create a user via an API call I get the 403 error and debug logs confirm it's failing on create.

              [2022-02-09 20:55:34] NOTICE: (403) No create access.; POST /User; line: 632, file: /var/www/html/application/Espo/Core/Record/Ser
              vice.php..................

              I'm totally stuck after several days of digging around trying to make this work so if you could share the steps you had success with that would be awesome!

              Comment


              • #8
                Originally posted by nicko View Post
                Hi guys, did you manage to successfully create a user via an API call? I'm not that great at PHP and JSON but it looks like the structure of EspoCRM has changed a lot in v7 onwards (I'm running 7.0.9), so i think some of the steps in the older posts on this forum no longer work for this. I've followed the steps to modify the User.json in Scope to give me access to assign Create permissions for User in role I can then assign to an API user, and I know the API user is good as I can successfully execute a GET to return users. However whenever I try a POST to create a user via an API call I get the 403 error and debug logs confirm it's failing on create.

                [2022-02-09 20:55:34] NOTICE: (403) No create access.; POST /User; line: 632, file: /var/www/html/application/Espo/Core/Record/Ser
                vice.php..................

                I'm totally stuck after several days of digging around trying to make this work so if you could share the steps you had success with that would be awesome!
                You have to give user which you use to connect through api permission to create users. Go to Administration -> Roles

                Comment


                • #9
                  Thanks for the reply

                  Yep that is the correct - I have a Role assigned to the API user that has Users: Create:yes, Read: all, Edit: all, Delete: all. I can verify the role is taking affect as if I change the Read permission to no and then attempt a GET, it fails with a 403, then if I switch Read back to all, it returns users ok.

                  Should this "just work" based on just modifying the scope User.json file and then updating the Role to include Create: yes

                  Comment


                  • #10
                    Originally posted by nicko View Post
                    Thanks for the reply

                    Yep that is the correct - I have a Role assigned to the API user that has Users: Create:yes, Read: all, Edit: all, Delete: all. I can verify the role is taking affect as if I change the Read permission to no and then attempt a GET, it fails with a 403, then if I switch Read back to all, it returns users ok.

                    Should this "just work" based on just modifying the scope User.json file and then updating the Role to include Create: yes
                    Could you show your request?

                    Comment


                    • #11
                      Yep sure, I'll attach a pic of the API from Integromat, and the JSON I'm sending is below.

                      {"type":"regular","firstName":"s34dsdf","lastName" :"w34erwerwe","isActive":true,"teams":{"teamsId s":[]},"gender":"","userName":"s34dfsdf@sdfsdf4747sd.co m","emailAddressData":[{"emailAddress":"s34dfsdf@sdfsdf4747sd.com","prima ry":true,"optOut":false,"invalid":false,"lower":"s 34dfsdf@sdfsdf4747sd.com"}],"emailAddress":"s34dfsdf@sdfsdf4747sd.com","email AddressIsOptedOut":false,"salutationName":null,"ro lesIds":["5ed4f6eec92414251"],"rolesNames":{"5ed4f6eec92414251":"Full User Access"},"password":"e76jcP3Uga","passwordConfirm" :"e76jcP3Uga","passwordPreview":"e76jcP3Uga","send AccessInfo":true,"title":null,"phoneNumberData":[],"phoneNumber":null,"phoneNumberIsOptedOut":null," teamsIds":[],"teamsNames":{},"teamsColumns":{},"defaultTeamNam e":null,"defaultTeamId":null}

                      Comment


                      • #12
                        Your request is bad. Please try this: https://dubas.pro/c/?5779a0d11efc1f7...kBFtQ1LiECpc64

                        Comment


                        • #13
                          Hey, thanks for checking, I've tried with that JSON but it's still 403. I also checked and if I intentionally make the JSON invalid I get a 500 as expected. What did you have to do on Espo to allow an API call to create a user?

                          Comment

                          Working...
                          X