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}
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>