QuickBlox Documentation

QuickBlox provides powerful Chat API and SDK to add real-time messaging and video calls to your web and mobile apps. Learn how to integrate QuickBlox across multiple platforms.

Users

Learn how to manage your users with QuickBlox.

The user module manages all things related to user accounts handling, authentication, account data, password remind, etc.

Before you begin

  1. Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.
  2. Register a QuickBlox account. This is a matter of a few minutes and you will be able to use this account to build your apps.
  3. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  4. Create a user session to be able to use QuickBlox functionality. See our Authentication page to learn how to do it.

Create user

Create a user using the code snippet below. Only login (or email) and password are required. Other fields are optional.

var params = {
  login: login,
  password: "someSecret",
  full_name: "QuickBlox Test"
};

QB.users.create(params, function(error, result) {
  if (error) {
    done.fail("Create user error: " + JSON.stringify(error));
  } else {
  }
});

Update user

Update a user profile using the following code snippet. If you want to change your password, you need to provide 2 parameters: password and old_password. The updated user entity will be returned.

var userId = 1,
  updatedUserProfile = {
    login: "johnsmith",
    full_name: "John Smith",
  };

QB.users.update(userId, updatedUserProfile, function (error, user) {});

Set user avatar

You can set a user's avatar. You just need to upload it to the QuickBlox cloud storage and then connect to a user.

// for example, a file from HTML form input field
var inputFile = $("input[type=file]")[0].files[0];

var fileParams = {
  name: inputFile.name,
  file: inputFile,
  type: inputFile.type,
  size: inputFile.size,
  public: false,
};

QB.content.createAndUpload(fileParams, function (error, result) {
  if (error) {
    // handle error
  } else {
    var userId = 1;
    var updatedUserProfile = {
      custom_data: JSON.stringify({ avatar_uid: result.uid }),
    };

    QB.users.update(userId, updatedUserProfile, function (error, user) {
      // handle update error or updated user
    });
  }
});

Now, other users can get you avatar.

var fileUID = JSON.parse(someUser.custom_data)['avatar_uid'];
var fileUrl = QB.content.privateUrl(fileUID);
var imageHTML = "<img src='" + fileUrl + "' alt='photo'/>";

Retrieve users

Retrieve users by ID

To get a list of users by ID for a current account, use the following code snippet.

var searchParams = {filter: { field: 'id', param: 'in', value: [22,33] }};
    
QB.users.listUsers(searchParams, function(error, result) {
     
});

Retrieve user by login

To get a list of users by login for a current account, use the following code snippet.

var searchParams = {login: "marvin18"};
    
QB.users.get(searchParams, function(error, user) {
    
});

Retrieve user by email

To get a list of users by email for a current account, use the following code snippet.

var searchParams = {email: "[email protected]"};
    
QB.users.get(searchParams, function(error, user) {
    
});

Retrieve users by full name

To get a list of users by full name for a current account, use the following code snippet.

var searchParams = {full_name: "Marvin Samuel"};
    
QB.users.get(searchParams, function(error, result) {
    
});

Retrieve users by phone number

To get a list of users by phone number for a current account, use the following code snippet.

var searchParams = {phone: "44678162873"};
    
QB.users.get(searchParams, function(error, result) {
    
});

Retrieve user by external user ID

If you have your own database with users (we call these databases as "external databases"), you can use External User IDExternal User ID - a unique identifier of the user in the integrated external system; used for cross-referencing. For example, a user has an internal user ID within the QuickBlox system and external ID, provided by the integrated external (client) system. When an API call with reference to the user has to be submitted, the user can be referenced by either internal or external identifiers. (ExternalID field) in QBUser model to link users from QuickBlox with users from your external database.

var searchParams = {external_user_id: "675373912"};
    
QB.users.get(searchParams, function(error, user) {
    
});

Retrieve users by tags

To get a list of users by tags for a current account, use the following code snippet.

var searchParams = {tags: ["apple"]};
    
QB.users.get(searchParams, function(error, result) {
    
});

Delete user

A user can delete himself from the platform.

var userId = 1;
QB.users.delete(userId, function(error, result) {
    
});

Reset user password

It's possible to reset a password via email.

QB.users.resetPassword("[email protected]", function(error) {
    
});

📘

By default, password reset functionality is turned off for Basic, Startup and Growth plans. Contact the sales team.

Updated 2 months ago


What's Next

Chat

Users


Learn how to manage your users with QuickBlox.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.