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.

let user = QBUUser()
user.login = "myLogin"
user.fullName = "myFullName"
user.password = "myPassword"

QBRequest.signUp(user, successBlock: { (response, user) in

}, errorBlock: { (response) in

})
QBUUser *user = [[QBUUser alloc] init];
user.login = @"myLogin";
user.fullName = @"myFullName";
user.password = @"myPassword";

[QBRequest signUp:user successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {
        
} errorBlock:^(QBResponse * _Nonnull response) {

}];

Retrieve users

Get a list of users using the users(withExtendedRequest:page:) method. The code snippet below shows how to get a list of users created between the two given dates and sorted in descending order.

let field = "created_at"
let typeField = "date"
let sortDesc = "desc"
let sortAsc = "asc"
let paramSort = "order"
let paramFilter = "filter[]"
let searchOperator = "between"
let searchValue = "2021-01-01, 2021-05-06"

var extendedRequest: [String: String] = [:]
extendedRequest[paramSort] = sortDesc + " " + typeField + " " + field
extendedRequest[paramFilter] = typeField + " " + field + " " + searchOperator + " " + searchValue
let page = QBGeneralResponsePage(currentPage: 1, perPage: 100)

QBRequest.users(withExtendedRequest: extendedRequest, page: page, successBlock: { (response, page, users) in
    
}, errorBlock: { response in
    
})
NSString *field = @"created_at";
NSString *typeField = @"date";
NSString *sortDesc = @"desc";
NSString *sortAsc = @"asc";
NSString *paramSort = @"order";
NSString *paramFilter = @"filter[]";
NSString *searchOperator = @"between";
NSString *searchValue = @"2021-01-01, 2021-05-06";

NSMutableDictionary *extendedRequest = [NSMutableDictionary dictionary];
extendedRequest[paramSort] =  [NSString stringWithFormat:@"%@ %@ %@", sortDesc, typeField, field];
extendedRequest[paramFilter] =  [NSString stringWithFormat:@"%@ %@ %@ %@", typeField, field, searchOperator, searchValue];

QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:10];

[QBRequest usersWithExtendedRequest:extendedRequest.copy page:page successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
    
}];

Argument

Required

Description

extendedRequest

yes

A dictionary that stores keys and values of the String type.

page

no

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

  • currentpage is a number of pages with results to be returned.
  • perPage is a number of records to return in one page.

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

Search operators

You can use search operators to get more specific search results. The request below will return a list of users created between the two given dates.

let field = "created_at"
let typeField = "date"
let paramFilter = "filter[]"
let searchOperator = "between"
let searchValue = "2021-01-01, 2021-05-06"

var extendedRequest: [String: String] = [:]
extendedRequest[paramFilter] = typeField + " " + field + " " + searchOperator + " " + searchValue
let page = QBGeneralResponsePage(currentPage: 1, perPage: 100)

QBRequest.users(withExtendedRequest: extendedRequest, page: page, successBlock: { (response, page, users) in

}, errorBlock: { response in
    
})
NSString *field = @"created_at";
NSString *typeField = @"date";
NSString *paramFilter = @"filter[]";
NSString *searchOperator = @"between";
NSString *searchValue = @"2021-01-01, 2021-05-06";

NSMutableDictionary *extendedRequest = [NSMutableDictionary dictionary];
extendedRequest[paramFilter] =  [NSString stringWithFormat:@"%@ %@ %@ %@", typeField, field, searchOperator, searchValue];

QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:10];

[QBRequest usersWithExtendedRequest:extendedRequest.copy page:page successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
    
}];

Here are the search operators that 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 a list of users sorted in descending order by the created_at field.

let field = "created_at"
let typeField = "date"
let sortDesc = "desc"
let sortAsc = "asc"
let paramSort = "order"

var extendedRequest: [String: String] = [:]
extendedRequest[paramSort] = sortDesc + " " + typeField + " " + field
let page = QBGeneralResponsePage(currentPage: 1, perPage: 100)

QBRequest.users(withExtendedRequest: extendedRequest, page: page, successBlock: { (response, page, users) in
    
}, errorBlock: { response in
    
})
NSString *field = @"created_at";
NSString *typeField = @"date";
NSString *sortDesc = @"desc";
NSString *sortAsc = @"asc";
NSString *paramSort = @"order";

NSMutableDictionary *extendedRequest = [NSMutableDictionary dictionary];
extendedRequest[paramSort] =  [NSString stringWithFormat:@"%@ %@ %@", sortDesc, typeField, field];

QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:10];

[QBRequest usersWithExtendedRequest:extendedRequest.copy page:page successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
    
}];

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.

let page = QBGeneralResponsePage(currentPage: 5, perPage: 10)      
QBRequest.users(withIDs: ["21","22"], page: page, successBlock: { (response, page, users) in
     
}, errorBlock:{ (response) in
    
})
QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:5 perPage:10];
[QBRequest usersWithIDs:@[@"20", @"21"] page:page successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
       
} errorBlock:^(QBResponse * _Nonnull response) {
                       
}];

Retrieve user by login

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

QBRequest.user(withLogin: "amigo", successBlock: { (response, user) in
    
}, errorBlock: { (response) in
    
})
[QBRequest userWithLogin:@"amigo" successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {
                
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Retrieve user by email

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

QBRequest.user(withEmail: "[email protected]", successBlock: { (response, user) in

}, errorBlock: { (response) in

})
[QBRequest userWithEmail:@"[email protected]" successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {
               
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Retrieve users by full name

To get a list of users found by the server according to the search query, use the following code snippet.

QBRequest.users(withFullName: "Amigo", page: nil, successBlock: { (response, page, users) in
       
}, errorBlock: { (response) in

})
[QBRequest usersWithFullName:@"Amigo" page:nil successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
                   
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Retrieve users by phone number

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

QBRequest.users(withPhoneNumbers: ["+4427123314"], page: nil, successBlock: { (response, page, users) in
   
}, errorBlock: { (response) in
    
})
[QBRequest usersWithPhoneNumbers:@[@"+4427123314"] page:nil successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
             
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

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.

QBRequest.user(withExternalID: 3789, successBlock: { response, user in
    
}, errorBlock: { (response) in
    
})
[QBRequest userWithExternalID:3789 successBlock:^(QBResponse * _Nonnull response, QBUUser *user) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Retrieve users by tags

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

QBRequest.users(withTags: ["iphone"], page: nil, successBlock: { (response, page, users) in
   
}, errorBlock: { (response) in

})
[QBRequest usersWithTags:@[@"iphone"] page:nil successBlock:^(QBResponse * _Nonnull response, QBGeneralResponsePage * _Nonnull page, NSArray<QBUUser *> * _Nonnull users) {
             
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Delete user

A user can delete himself from the platform.

QBRequest.deleteCurrentUser(successBlock: { (response) in
    
}, errorBlock: { (response) in
    
})
[QBRequest deleteCurrentUserWithSuccessBlock:^(QBResponse * _Nonnull response) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
                 
}];

Reset user password

It's possible to reset a password via email.

QBRequest.resetUserPassword(withEmail: "[email protected]", successBlock: { (response) in
            
}, errorBlock: { (response) in
               
})
[QBRequest resetUserPasswordWithEmail:@"[email protected]" successBlock:^(QBResponse * _Nonnull response) {

} errorBlock:^(QBResponse * _Nonnull response) {

}];

📘

By default, a 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 oldPassword. The updated user entity will be returned.

🚧

You must set null into the user's password field if you do not want to change your password, otherwise, you will need to add the user's old password to the oldPassword field.

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.

guard let currentUser = QBSession.current.currentUser else { return }
var customData:[String: String] = [:]

if let data = currentUser.customData?.data(using: .utf8),
   let currentUserCustomData = try? JSONSerialization.jsonObject(with: data, options: []) as! [String : String]  {
    customData = currentUserCustomData
}
customData["name"] = "John"
customData["age"] = "31"
customData["city"] = "New York"

let updateUserParameter = QBUpdateUserParameters()
guard let customJSONData = try? JSONSerialization.data(withJSONObject:  customData, options: .prettyPrinted) else { return }
updateUserParameter.customData = String(data: customJSONData, encoding: .utf8)
//example of custom data JSON string
let userCustomDataJsonStringExample = "{\"name\" : \"John\", \"age\" : \"31\", \"city\" : \"New York\"}"
     
updateUserParameter.tags = ["quickblox", "test", "QADev", "chat", "videochat", "webrtc", "conference"]

QBRequest.updateCurrentUser(updateUserParameter, successBlock: {response, user in

}, errorBlock: { (response) in

})
QBUUser *currentUser = QBSession.currentSession.currentUser;
NSMutableDictionary *customData = [NSMutableDictionary dictionary];

if (currentUser.customData) {
    NSData *currentUserJsonData = [currentUser.customData dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *currentUserCustomData = [NSJSONSerialization JSONObjectWithData:currentUserJsonData options:kNilOptions error:nil];
    customData = currentUserCustomData.mutableCopy;
}
customData[@"name"] = @"John";
customData[@"age"] = @"31";
customData[@"city"] = @"New York";

QBUpdateUserParameters *updateUserParameter = [[QBUpdateUserParameters alloc] init];
NSData *jsonCustomData = [NSJSONSerialization dataWithJSONObject:customData options:NSJSONWritingPrettyPrinted error:nil];
NSString *jsonCustomDataString = [[NSString alloc] initWithData:jsonCustomData encoding:NSUTF8StringEncoding];

updateUserParameter.customData = jsonCustomDataString;
//example of custom data JSON string
NSString *userCustomDataJsonStringExample = @"{\"name\" : \"John\", \"age\" : \"31\", \"city\" : \"New York\"}";

updateUserParameter.tags = @[@"quickblox", @"test", @"QADev", @"chat", @"videochat", @"webrtc", @"conference"];

[QBRequest updateCurrentUser:updateUserParameter successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
    
}];

Field

Required

Description

tags

no

User tags. An array of Strings. A tag must include alphabetic characters only. The tag must be at least 3 and no more than 15 characters long. 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.

customData

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, just convert the file to the date format and upload it to the QuickBlox cloud storage by calling the tUploadFile(fileName:contentType:isPublic:) method. In the response, the uploadedBlob object is returned by the server. Get the blob UID from the uploadedBlob object.

To connect the file to the user, set the blob UID in the customData field of the user model and call the updateCurrentUser() method. As a result, the user avatar gets updated.

let image = UIImage(systemName: "person.circle")
guard let imageData = image?.pngData() else {
    return
}

let fileName = "avatar.png"
let contentType = "image/png"
let isPublic = true
QBRequest.tUploadFile(imageData, fileName: fileName, contentType: contentType, isPublic: isPublic, successBlock: { (response, uploadedBlob) in
    let parameters = QBUpdateUserParameters()
    parameters.blobID = uploadedBlob.id
    
    QBRequest.updateCurrentUser(parameters, successBlock: { (response, user) in
        
    }, errorBlock: { (response) in
        
    })
    
}, statusBlock: { (request, status) in
    
}, errorBlock: { (response) in
    
})
UIImage *image = [UIImage systemImageNamed:@"person.circle"];
NSData *imageData = UIImagePNGRepresentation(image);
NSString *fileName = @"avatar.png";
NSString *contentType = @"image/png";
BOOL isPublic = TRUE;

[QBRequest TUploadFile:imageData fileName:fileName contentType:contentType isPublic:isPublic successBlock:^(QBResponse * _Nonnull response, QBCBlob * _Nonnull uploadedBlob) {
    
    QBUpdateUserParameters *parameters = [[QBUpdateUserParameters alloc] init];
    parameters.blobID = uploadedBlob.ID;
    
    [QBRequest updateCurrentUser:parameters successBlock:^(QBResponse * _Nonnull response, QBUUser * _Nonnull user) {
        
    } errorBlock:^(QBResponse * _Nonnull response) {
        
    }];
    
} statusBlock:^(QBRequest * _Nonnull request, QBRequestStatus * _Nonnull status) {
    
} errorBlock:^(QBResponse * _Nonnull response) {
    
}];

Pass the following arguments to the updateCurrentUser() method.

Argument

Required

Description

parameters

yes

Specifies parameters fields that should be set.

Now, other users can get your avatar by calling the downloadFile(withUID:) method.

let userAvatarImageView = UIImageView()
let user = QBSession.current.currentUser
QBRequest.blob(withID: user.blobID, successBlock: { (response, blob) in
    
    guard let blobUID = blob.uid else {return}
    QBRequest.downloadFile(withUID: blobUID, successBlock: { (response, fileData)  in
        if let image = UIImage(data: fileData) {
            userAvatarImageView.image = image
        } 
    }, statusBlock: { (request, status) in
        
    }, errorBlock: { (response) in
        
    })
    
}, errorBlock: { (response) in
    
})
UIImageView *userAvatarImageView = [[UIImageView alloc] init];
QBUUser *user = QBSession.currentSession.currentUser;
[QBRequest blobWithID:user.blobID successBlock:^(QBResponse * _Nonnull response, QBCBlob * _Nonnull tBlob) {
    
    [QBRequest downloadFileWithUID:tBlob.UID successBlock:^(QBResponse * _Nonnull response, NSData * _Nonnull fileData) {
        UIImage *image = [UIImage imageWithData:fileData];
        userAvatarImageView.image = image;
    } statusBlock:^(QBRequest * _Nonnull request, QBRequestStatus * _Nonnull status) {
        
    } errorBlock:^(QBResponse * _Nonnull response) {
        
    }];
    
} errorBlock:^(QBResponse * _Nonnull response) {
    
}];

Argument

Required

Description

avatarUID

yes

Blob unique identifier.

Updated 16 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.