List all users
getUsers() returns a paginated list of all users with their metadata.
Requires App Context
Enable App Context in the Admin Portal to store user data. If using Access Manager, uncheck Disallow Get All User Metadata in the App Context configuration.
Method signature
This method takes the following parameters:
1chat.getUsers(
2 filter: String?,
3 sort: Collection<PNSortKey<PNKey>> = listOf(),
4 limit: Int?,
5 page: PNPage?,
6): PNFuture<GetUsersResponse>
Input
* required
| Parameter | Description |
|---|---|
filterType: StringDefault: 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. |
sortType: Collection<PNSortKey<PNKey>>Default: 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. |
limitType: IntDefault: 100 | Number of objects to return in response. The default (and maximum) value is 100. |
pageType: PNPageDefault: 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). |
Sample code
Fetch all existing user IDs.
1// reference the "chat" object and invoke the "getUsers()" method
2chat.getUsers().async { result ->
3result.onSuccess {
4 // handle success
5 }.onFailure {
6 // handle failure
7 }
8}
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.
1chat.getUsers(limit = 25).async { result ->
2 result.onSuccess { usersObject: GetUsersResponse ->
3 chat.getUsers(limit = 25, page = usersObject.next)
4 .async { result2 ->
5 result2.onSuccess { usersObjectPage2 -> ... }
6 .onFailure { ... }
7 }
8 }.onFailure { ... }
9}
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.
1chat.getUsers(filter = "status=='deleted'").async { result ->
2 result.onSuccess { getUsersResponse: GetUsersResponse ->
3 // handle success
4 println("Number of soft deleted users is: ${getUsersResponse.users.size}")
5 }.onFailure { e: PubNubException ->
6 // handle failure
7 }
8}