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.

Visit our Key Concepts page to get an overall understanding of the most important QuickBlox concepts.

Before you begin

  1. 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.
  2. Configure QuickBlox SDK for your app. Check out our Setup page for more details.
  3. 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 {
  }
});

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.

Update user

Update a user profile by calling the updateUser() method. If you want to change your password, you need to provide 2 parameters: password and old_password. As a result, the updated user entity will be returned.

You can update any other field of the user using the update() method. Thus, the snippet below shows how to update a tag_list and custom_data fields.

var userId = 1,
custom_data = JSON.stringify({ 
  name: 'John',
  age: 31,
  city: 'New York'
}),
    
updatedUserProfile = {
  tag_list: 'tagOne,tagTwo',
  custom_data
};

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

Field

Required

Description

tag_list

no

User tags. An array of Strings. There are no spaces in the tag format. For example, the "tagOne" format is correct while the "tag one" format is incorrect.

The maximum number of tags is 10. If more than 10 tags are provided, an error is returned: tag list should contain maximum 10 tags.

custom_data

no

User custom data. Should be a String. You can convert any data types to String, or example, JSON, XML, etc.

Set user avatar

To set a user avatar, just upload a file to the QuickBlox cloud storage and connect it to the user.

To upload the file to the QuickBlox cloud storage, call the createAndUpload() method. Now that the file is uploaded, get the ID of the uploaded file.

To connect the file to the user, set the ID of the uploaded file to the blob_id field of the user and call the update() method. As a result, the user avatar gets updated.

// 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) {
  } else {
    var userId = 1;
    var updatedUserProfile = {
      blob_id: result.id
    };

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

Pass the following arguments to the update() method.

Argument

Required

Description

userId

yes

User ID.

updatedUserProfile

yes

Specifies the updatedUserProfile fields that should be set.

function

yes

Specifies a callback function that accepts an error and updated user entity.

Now, other users can get access to your avatar by using the code snippet below. As a result, you will receive a private URL in the response. See this section to learn more about file URLs.

var fileId = someUser.blob_id;
QB.content.getInfo(fileId, function(error, result) {
  if (error) {
    done.fail("Get file information by ID error: " + JSON.stringify(error));
  } else {
    var fileUID = result.blob.uid;
    
        var fileUrl = QB.content.privateUrl(fileUID);
        var imageHTML = "<img src='" + fileUrl + "' alt='photo'/>";
  }
});

Updated 15 days 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.