List all users
Get a paginated list of all users and their details using the getUsers()
method.
By default, this method returns all custom user metadata without the need to define that during the call explicitly.
Requires App Context
To store data about users, you must enable App Context for your app's keyset in the Admin Portal.
If you have Access Manager enabled in your app, uncheck the Disallow Get All User Metadata
option in the App Context configuration in the Admin Portal – this way you can get metadata of all users without the need to define that in the permissions schema included in the authentication token.
Method signature
This method takes the following parameters:
chat.getUsers(
filter: String?,
sort: Collection<PNSortKey<PNKey>> = listOf(),
limit: Int?,
page: PNPage?,
): PNFuture<GetUsersResponse>
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
filter | String | No | n/a | Expression used to filter the results. Returns only these users whose properties satisfy the given expression are returned. The filtering language is defined here. |
sort | Collection<PNSortKey<PNKey>> | No | listOf() | A collection to specify the sort order. Available options are id , name , and updated . Use asc or desc to specify the sorting direction, or specify null to take the default sorting direction (ascending). For example: {name: "asc"} . Unless specified otherwise, the items are sorted by the last updated date. Defaults to an empty list. |
limit | Int | No | 100 | Number of objects to return in response. The default (and maximum) value is 100 . |
page | PNPage | No | n/a | Object used for pagination to define which previous or next result page you want to fetch. |
Output
Type | Description |
---|---|
PNFuture<GetUsersResponse> | PNFuture containing a set of users with pagination information (next , prev , total ). |
Basic usage
Fetch all existing user IDs.
// reference the "chat" object and invoke the "getUsers()" method
chat.getUsers().async { result ->
result.onSuccess {
// handle success
}.onFailure {
// handle failure
}
}
Other examples
Pagination
Get the total number of 25 users and then specify that you want to fetch the results from the next page using a string that was previously returned from the PubNub server.
chat.getUsers(limit = 25).async { result ->
result.onSuccess { usersObject: GetUsersResponse ->
chat.getUsers(limit = 25, page = usersObject.next)
.async { result2 ->
result2.onSuccess { usersObjectPage2 -> ... }
.onFailure { ... }
}
}.onFailure { ... }
}
Archived users
Get all archived users. This request will return all users removed with the soft
option set to true
, whose data is still stored in the App Context storage.
chat.getUsers(filter = "status=='deleted'").async { result ->
result.onSuccess { getUsersResponse: GetUsersResponse ->
// handle success
println("Number of soft deleted users is: ${getUsersResponse.users.size}")
}.onFailure { e: PubNubException ->
// handle failure
}
}