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(
string filter = "",
string sort = "",
int limit = 0,
Page page = null
)
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
filter | string | No | empty string | Expression used to filter the results. Returns only these memberships whose properties satisfy the given expression. The filter language is defined here. |
sort | string | No | empty string | Key-value pair of a property to sort by, and a sort direction. 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"} . By default, the items are sorted by the last updated date. |
limit | int | No | 0 | Number of objects to return in response. |
page | Page | No | null | Object used for pagination to define which previous or next result page you want to fetch. |
Output
Type | Description |
---|---|
UsersResponseWrapper | An object containing the filtered, sorted, and paginated list of users. |
Basic usage
Fetch all existing user IDs.
// fetch all existing users
var usersWrapper = chat.GetUsers();
// check if users were successfully fetched
if (users != null)
{
Console.WriteLine("Existing user IDs:");
// loop through the users and print their IDs
foreach (var user in usersWrapper.Users)
{
Console.WriteLine(user.Id);
}
}
else
show all 18 linesOther 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.
// fetch the initial 25 users
var initialUsers = chat.GetUsers(limit: 25);
Console.WriteLine("Initial 25 users:");
foreach (var user in initialUsers.Users)
{
Console.WriteLine($"Id: {user.Id}, UserName: {user.UserName}, Status: {user.Status}");
}
// fetch the next set of users using the pagination token
var nextUsers = chat.GetUsers(limit: 25, page: initialUsers.Page);
Console.WriteLine("\nNext users:");
foreach (var user in nextUsers.Users)
{
show all 17 linesDeleted users
Return all users with the deleted
status.
var deletedUsers = chat.GetUsers(filter: "Status='deleted'");
foreach (var user in deletedUsers.Users)
{
Console.WriteLine($"Id: {user.Id}, UserName: {user.UserName}, Status: {user.Status}");
}