Chat / JavaScript
Chat JavaScript v4
Chat JavaScript
Chat
JavaScript
Home
/
Chat
/
JavaScript
/
User
This is the new Docs for Chat SDK v4 for JavaScript. To see the previous Docs, click here.

Retrieve a list of users in an application

You can retrieve a list of all or certain users in your Sendbird application using an ApplicationUserListQuery instance. The next() method returns a list of User objects which contain information on users within the application.

const queryParams: ApplicationUserListQueryParams = {
    limit: 20
};
const query = sb.createApplicationUserListQuery(queryParams);

const users = await query.next();

ApplicationUserListQuery

Using a number of different parameters the ApplicationUserListQuery instance provides, you can retrieve a list of specific users that match the set values in the parameters. Currently the ApplicationUserListQuery instance supports the following parameters.

List of parameters

Parameter nameTypeDescription

UserIdsFilter

string

Specifies the unique IDs of users you want to retrieve in the filter.

MetaDataKeyFilter

string

Specifies a metadata key to retrieve users with metadata containing an item with the specified key and values. Both metaDataKeyFilter and metaDataValuesFilter must be specified.

MetaDataValuesFilter

string

Specifies the metadata values to retrieve users with metadata containing an item with the specified key and values. Both metaDataKeyFilter and metaDataValuesFilter must be specified.

NicknameStartsWithFilter

string

Specifies user nicknames to retrieve users whose nicknames start with the specified value.

Note: We recommend you set the maximum number of user IDs to 250 in the UserID filter. If exceeded, your query may receive an HTTP 414 error indicating that the submitted request data is longer than the Sendbird server is willing to interpret.

// Retrieve certain users using the userIdsFilter parameter.
const queryParams: ApplicationUserListQueryParams = {
    userIdsFilter: ['Harry', 'Jay', 'Jin'],
};
const query = sb.createApplicationUserListQuery(queryParams);

const users = await query.next();

// Retrieve certain users using the metaDataKeyFilter and metaDataValuesFilter parameters.
const queryParams: ApplicationUserListQueryParams = {
    metaDataKeyFilter: 'hobby',
    metaDataValuesFilter: ['movie', 'book', 'exercise'],
};
const query = sb.createApplicationUserListQuery(queryParams);

const users = await query.next();

// Retrieve certain users using the nicknameStartsWithFilter parameter.
const queryParams: ApplicationUserListQueryParams = {
    nicknameStartsWithFilter: 'Ja',
};
const query = sb.createApplicationUserListQuery(queryParams);

const users = await query.next();