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.

🚧

This is our new documentation for beta version of QuickBlox React Native SDK. Please contact our Customer Support Team to provide your feedback, suggestions, and requests to improve this page.

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.

QB.users
  .create({
    email: '[email protected]',
    fullName: 'Jack Sparrow',
    login: 'jack',
    password: 'jackpassword',
    phone: '404-388-5366',
    tags: ['awesome', 'quickblox']
  })
  .then(function (user) {
    // user created successfully
  })
  .catch(function (e) {
    // handle as necessary
  });

Retrieve users

Retrieve users by ID

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

const occupantsIds = dialog.occupantsIds;
const filter = {
  field: QB.users.USERS_FILTER.FIELD.ID,
  type: QB.users.USERS_FILTER.TYPE.NUMBER,
  operator: QB.users.USERS_FILTER.OPERATOR.IN,
  value: occupantsIds.join()
};

QB.users
  .getUsers({ filter: filter })
  .then(function (result) {
    // result.users - array of users found by provided IDs
    // result.page - page of results
    // result.perPage - how much items returned per page
    // result.total - total amount of items
  })
  .catch(function (e) {
    // handle error
  });

Retrieve users by full name

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

const filter = {
  field: QB.users.USERS_FILTER.FIELD.FULL_NAME,
  operator: QB.users.USERS_FILTER.OPERATOR.IN,
  type: QB.users.USERS_FILTER.TYPE.STRING,
  value: 'filter'
};

QB.users
  .getUsers({ filter: filter })
  .then(function (result) {
    // users found
  })
  .catch(function (e) {
    // handle error
  });

Update user

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

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

const user = {
  customData: JSON.stringify({
    name: 'John',
    age: 31,
    city: 'New York'
  }),
  tags: ['testOne', 'tagTwo']
};
 
QB.users
  .update(user)
  .then(function (updatedUser) {
    // update local user information with the data server returned
  })
  .catch(function (e) {
    // handle error
  });

Field

Required

Description

customData

no

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

tags

no

User tags. An array of Strings. A tag must include alphanumeric characters only and start with a letter. 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 that 10 tags are provided, an error is returned: Error: tag list should contain maximum 10 tags

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 upload() method and pass the fileUrl to it. The fileUrl is a path to the file in the device filesystem. 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 blobId field of the user and call the update() method. As a result, the user avatar gets updated.

const fileUrl = "path to file in device's filesystem";
const fileData = {
  url: fileUrl,
  public: false
};

QB.content
  .upload(fileData)
  .then(function (file) {
    // file uploaded successfully
    const userUpdate = { blobId: file.id };
    return QB.users.update(userUpdate);
  })
  .then(function (user) {
    // user updated successfully
  })
  .catch(function (error) {
    // inspect error message to check what is wrong
  });

Set the following fields of the userUpdate:

Field

Required

Description

blobId

no

User blob ID.

You can also get access to the uploaded avatar of the user by calling the getPrivateURL() method. As a result, you will receive a private URL in the response. See this section to learn more about file URLs and getInfo() method.

const fileInfoRequest = {
  id: user.blobId
};

// get access to the avatar that was set in user's "blobId" property
QB.content
  .getInfo(fileInfoRequest)
  .then(function (file) {
    const fileUrlRequest = { uid: file.uid };
    return QB.content.getPrivateUrl(fileUrlRequest);
  })
  .then(function (imageUrl) {
    // <Image source={{ uri: imageUrl }} />
  })
  .catch(function (error) {
    // inspect error message to check what is wrong
  });

Pass the following argument to the getPrivateUrl() method.

Argument

Required

Description

fileUrlRequest

yes

Specifies fileUrlRequest object with uid property. The uid is a file unique indetifier.

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.