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

Get a list of users using the listUsers() method. The code snippet below shows how to get a list of users created between the two given dates, sorted in ascending order, with 50 users on the page.

var params = {
  filter: {
    field: "created_at",
    param: 'between',
    value: '2021-01-01, 2021-05-06'
  },
  order: {
    field: 'created_at',
    sort: 'asc'
  },
  page: 1,
  per_page: 50
};

QB.users.listUsers(params, function(error, result){

});

If you want to retrieve only users updated after some specific date time, you can use operators. This is useful if you cache users somehow and do not want to obtain the whole list of your users on every app start. Thus, you can use search and sort operators to list users on the page so that it is easier to see specific users.

If you want to get a paginated list of users from the server, you can set the following fields of the filter:

Field

Required

Description

page

no

Number of pages with results to be returned.

per page

no

Number of records to return in one page.

Search operators

You can use search operators to get more specific search results. The request below will return users by IDs.

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

Here are the search operators you can use to search for the exact data that you need.

Search operators

Applicable to types

Applicable to fields

Description

lt

number, string, date

id, created_at, updated_at, last_request_at, external_user_id, facebook_id

Less Than operator.

gt

number, string, date

id, created_at, updated_at, last_request_at, external_user_id, facebook_id

Greater Than operator.

gte

number, string, date

id, created_at, updated_at, last_request_at, external_user_id, facebook_id

Greater Than or Equal to operator.

le

number, string, date

id, created_at, updated_at, last_request_at, external_user_id, facebook_id

Less or Equal to operator

eq

number, string, date

id, full_name, email, login, phone, created_at, updated_at, last_request_at, external_user_id, facebook_id

Equal to operator.

ne

number, string, date

id, full_name, email, login, phone, created_at, updated_at, last_request_at, external_user_id, facebook_id

Not Equal to operator.

between

number, string, date

id, created_at, updated_at, last_request_at, external_user_id, facebook_id

Contained between values operator.

in

number, string, date

id, full_name, email, login, phone, created_at, updated_at, last_request_at, external_user_id, facebook_id

IN array operator.

Sort operators

You can use sort operators to order the search results. The request below will return users by the created_at field sorted in descending order.

var params = {
  filter: {
    field: "created_at",
    param: 'between',
    value: '2021-01-01, 2021-05-06'
  },
  order: {
    field: 'created_at',
    sort: 'desc'
  },
};

QB.users.listUsers(params, function(error, result){

});

Here are the sort operators you can use to order the search results.

Sort operator

Applicable to types

Applicable to fields

Description

asc

All types

id, full_name, email, login, phone, website, created_at, updated_at,
last_request_at, external_user_id

Search results will be sorted in ascending order by the specified field.

desc

All types

id, full_name, email, login, phone, website, created_at, updated_at,
last_request_at, external_user_id

Search results will be sorted in descending order by the specified field.

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", //substring search
  order: {
    field: 'updated_at',
    sort: 'desc'
  },
  page: 1,
  per_page: 50
};
    
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) {
    
});

🚧

Make sure to enable the email confirmation. This functionality allows application users to confirm their emails. If a user doesn't confirm the email, the emails won't be sent to this user. As a result, a password reset functionality won't work. To enable the email confirmation, proceed as follows:

  1. Go to the Dashboard => YOUR_APP => Users => Settings => User registration confirmation and check the box.
  2. Click the Save button.

📘

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 26 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.