User Management

With the user management API, you can create, delete users, update your profile information, add friends to your profile, remove friends from your profile.

Note that this user management will only work with CometChat v5.7 and custom coded integration.

To add User Management support in your application,

Include CustomUI.js in your index.html file to access the Custom UI functionality in your Cordova app

All the method calls will invoke their respective callback blocks as defined below.

The API key can be obtained from CometChat administration panel. For this, perform following steps.

  1. login to your CometChat admin
  2. Goto settings tab, at the bottom you will find following lines
  3. APIkey

1. Create user
Create a user with given userName and password. (Ensure that userName and password cannot be nil or empty)


function callbackmeth(result){

   alert(result);

}

CustuomUI.createUser(apikey,username,password,link,avatar,displayname,callbackmeth);

Parameters:
(i). apikey: Api-Key from CometChat Administration Panel (Settings)
(ii). userName: Name of the user
(iii). password: Password to login to CometChat
(iv). link: Link associated with the user
(v). avatar: Avatar of the user
(vi). displayName: Explicit name of the user to be displayed

Invocation: After the user is created successfully.
Response: Callback containing the status and the message
Eg:

"success"={
   "status" = "1000";
   "message" = "User created successfully!";
   "data" = {
             "userid" = 28;
            }
}

2. Update user details
Update any of the following user details. originalPassword is required to change any detail.(Ensure that originalPassword cannot be nil or empty)


function callbackmeth(result){

   alert(result);

}

CustomUI.updateDisplayName(apikey,displayname,newPassword,link,avatarPath,userID,originalPassword,flag,callbackmeth);

Parameters:
(i). apikey: Api-Key from CometChat Administration Panel (Settings)
(ii). displayName: Display name of the user to be updated
(iii). newPassword: Password of the user to be updated
(iv). link: Link of the user to be updated
(v). avatar: Avatar of the user to be updated
(vi). userID: userID of the user whose details have to be updated. If userID is NULL then details of the logged-in user will be updated.
(vii). originalPassword: Current password of the user whose details have to be updated.
If userID is NULL then pass the logged-in user’s current password
(vii). flag: If flag = YES, NULL OR empty values i.e @”” passed will be updated to default/empty values
If flag = NO, NULL OR empty values i.e @”” passed will not be updated

Invocation: After the user’s details have been updated successfully.
Response: NSDictionary containing the status and the message
Eg:

"success"={
     "status" = "1000";
     "message" = "Details updated successfully!";
}

3. Remove user
Remove/Delete a user from CometChat by providing userID. (Ensure that userID cannot be nil or empty)


function callbackmeth(result){

   alert(result);

}

CustomUI.removeUserByID("28",callbackmeth);

Invocation: After the user is removed successfully.
Response: Callback containing the status and the message
Eg:

"success"={
       "status" = "1000";
       "message" = "User deleted successfully!";
       "data" = {
                 "userid" = "28"
                }
}

4. Add friends
Add friends to logged-in user by providing array of user’s ID. (Ensure that userIDArray cannot be nil or empty)


function callbackmeth(result){

   alert(result);

}

CustomUI.addFriends("4e7988f4b5a62c6926006fec9da07923",["2","3","43"],callbackmeth);

Invocation: After the user/users have been added successfully.
Response: Callback containing the status and the message
Eg:

"success"={
      "status" = "1000";
      "message" = "Friends added successfully!";
      "data" = {
                "userid":"4"
               }
}

Here, data will contain the userID of only those users who have been added successfully

5. Remove friends
Remove friends of logged-in user by providing array of user’s ID.(Ensure that userIDArray should not be nil or empty)


function callbackmeth(result){

   alert(result);

}
CustomUI.removeFriends(["2","3","45"],callbackmeth);

Parameters:
(i). userIDArray: An array containing user’s ID who have to be removed as friends

Invocation: After the user/users have been removed successfully.
Response: NSDictionary containing the status and the message
Eg:

"success"={
       "status" = "1000";
       "message" = "Friends removed successfully!";
       "data" = {
                 "userid":"4"
               }
}

Here, data will contain the userid of only those users who have been removed successfully

Please refer ‎error codes for failure responses.

Not finding what you need?

The CometChat team is here to help!