Adding Collaborators and annotating documents with web app users

Ok…I’ve specified the id and apps parameters, and I’m getting another error. See below:


12:34:46.694 (2694375774)|CALLOUT_REQUEST|[57]|System.HttpRequest[Endpoint=https://metrics.groupdocs.com/]
12:34:46.890 (2890281429)|CALLOUT_RESPONSE|[57]|System.HttpResponse[Status=OK, StatusCode=200]
12:34:46.890 (2890319404)|SYSTEM_METHOD_EXIT|[57]|System.Http.send(ANY)
12:34:46.890 (2890350649)|SYSTEM_METHOD_ENTRY|[58]|system.Type.getName()
12:34:46.890 (2890376916)|SYSTEM_METHOD_EXIT|[58]|system.Type.getName()
12:34:46.890 (2890407732)|SYSTEM_METHOD_ENTRY|[61]|System.HttpResponse.getBody()
12:34:46.890 (2890464476)|SYSTEM_METHOD_EXIT|[61]|System.HttpResponse.getBody()
12:34:46.890 (2890487845)|SYSTEM_METHOD_ENTRY|[62]|System.debug(ANY)
12:34:46.890 (2890497376)|USER_DEBUG|[62]|DEBUG|JSON response from server: {“result”:{“id”:0,“guid”:null,“primary_email”:null},“status”:“Failed”,“error_message”:“A user with the same name is already registered in the system.”,“composedOn”:1433349286900}

I’m verifying that the information is correct in the GD_UserInfo object before I call UpdateAccountUser:
12:34:46.687 (2687048708)|USER_DEBUG|[130]|DEBUG|SiteTraker Debug: Nickname:Bob Sirius
12:34:46.687 (2687247065)|USER_DEBUG|[130]|DEBUG|SiteTraker Debug: firstname:Bob
12:34:46.687 (2687434775)|USER_DEBUG|[130]|DEBUG|SiteTraker Debug: lastname:Sirius
12:34:46.687 (2687554904)|USER_DEBUG|[130]|DEBUG|SiteTraker Debug: email:bobbosirius2@gmail.com

Also, this is an email address I created specifically for testing groupdocs.  I created the address one minute before running the createUser method, so there is no way it could exist in the system.

Also, when I look at the Users from our GroupDocs console, I dont even see this user…

Here is the complete method I’ve written to create an account user:

public GD_UserInfo createUser() {

    GD_GroupDocsSecurityHandler securityHandler = new GD_GroupDocsSecurityHandler(GD_Utils.privateKey);
    GD_ApiClient api = new GD_ApiClient(securityHandler);
    GD_MgmtApi mgmtApi = new GD_MgmtApi(api);
    //Check if user exists:
    String userEmail = UserInfo.getUserEmail();
    GD_GetAccountUsersResponse userResp = mgmtApi.GetAccountUsers(GD_Utils.clientId);
    List<GD_UserInfo> users = userResp.result.users;
    for(GD_UserInfo user : users){
        if(userEmail.equalsIgnoreCase(user.primary_email)){
            //User found, don't recreate
            status += 'createUser guid (found): ' + user.guid;
            return user;
        }
    }

    GD_UserInfo userObj = new GD_UserInfo();
    GD_RoleInfo role = new GD_RoleInfo();
    List<GD_RoleInfo> rolesList = new List<GD_RoleInfo>();

//Set user role Id. Can be: 1 - SysAdmin, 2 - Admin, 3 - User, 4 - Guest
role.name = ‘User’;
role.id = 3;
//Set user role name. Can be: SysAdmin, Admin, User, Guest
userObj.nickname= UserInfo.getFirstName() + ’ ’ + UserInfo.getLastName();
StUtils.StDebug(‘Nickname:’ + userObj.nickname);
userObj.firstname = UserInfo.getFirstName();
StUtils.StDebug(‘firstname:’ + userObj.firstname);
userObj.lastname = UserInfo.getLastName();
StUtils.StDebug(‘lastname:’ + userObj.lastname);
userObj.primary_email = userEmail;
StUtils.StDebug(‘email:’ + userObj.primary_email);
userObj.id = 0;
userObj.apps=‘127’;
userObj.alerts_eanbled = false;
rolesList.add(role);
userObj.roles=rolesList;

    GD_UpdateAccountUserResponse  createAccountUserResponse = mgmtApi.UpdateAccountUser(GD_Utils.clientId, userEmail, userObj);
     string status = createAccountUserResponse.status;
    if (status.containsIgnoreCase('ok')) {
        GD_UpdateAccountUserResult result = createAccountUserResponse.result;
        String newUserGuid = result.guid;
        status += 'newUserGuid: ' + newUserGuid;
        userObj.guid = newUserGuid;
    }else {
            this.status =createAccountUserResponse.error_message;
            
        }
    return userObj;
}</span></font></pre><pre class="codeBlock" style="background-color: rgb(248, 248, 248);"><font face="Courier New, Courier, mono"><span style="font-size: 12px;"><br></span></font></pre><pre class="codeBlock" style="background-color: rgb(248, 248, 248);"><font face="Courier New, Courier, mono"><span style="font-size: 12px;">Now, when I create a new user via the console and run this method, it finds the existing user without a problem, sets the user as a collaborator, and annotating works fine.  So once the issue of creating a user is fixed, we should be good to go.  </span></font></pre></div>
Hello Bob,

We have checked with product team the email "bobbosirius2@gmail.com" and in our GroupDocs system this user is already registered. You should notice that you can't register two users with the same email. If users already exist in our system you will get such message. You can't check if users already registered via the GetAccountUsers method, because it will return you only users from your account.

Also we have checked your account and found out that you already added two users to your account:
AccountId UserName
124750 mb@mavengrp.com
124750 192d5bbc41
124750 35f1f7c785

If you need to check user adding functional, first remove users which you already have added. You can use the GroupDocs Dashboard or the DeleteAccountUser method, to delete the users.

Best regards
Evgen Efimov

http://groupdocs.com
Your Document Collaboration APIs
Follow us on LinkedIn, Twitter, Facebook and Google+

Evgen,


If I’m calling UpdateAccountUser to create a new account user, shouldn’t that user be included in the results when I query using GetAccountUsers ?
Hello Bob,

Yes, if you add new user in to your account via the UpdateAccountUser method, then you can call the GetAccountUsers method and it will return all users from your account.

If you will have more questions please feel free to contact us.

Best regards
Evgen Efimov

http://groupdocs.com
Your Document Collaboration APIs
Follow us on LinkedIn, Twitter, Facebook and Google+