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

icon

Under the hood


This method takes the following parameters:

chat.getUsers({
filter?: string,
sort?: object,
limit?: number,
page?: {
next?: string,
prev?: string,
}
}): Promise<{
users: User[],
page: {
next: string,
prev: string,
},
total: number,
show all 16 lines

Input

ParameterTypeRequiredDefaultDescription
filterstringNon/aExpression used to filter the results. Returns only these users whose properties satisfy the given expression are returned. The filtering language is defined here.
sortobjectNon/aKey-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.
limitnumberNo100Number of objects to return in response. The default (and maximum) value is 100.
pageobjectNon/aObject used for pagination to define which previous or next result page you want to fetch.
 → nextstringNon/aRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
 → prevstringNon/aRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.

Output

ParameterTypeDescription
Promise<>objectReturned object containing three fields: users, page, and total.
 → usersUser[]List of all matching users.
 → pageobjectString that lets you either fetch the next (next) or previous (prev) result page.
   → nextstringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
   → prevstringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data. Ignored if the next parameter is supplied.
 → totalnumberTotal number of User objects matching the request query.

Basic usage

Fetch all existing user IDs.

// reference the "chat" object and invoke the "getUsers()" method
const users = await chat.getUsers()

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.

// result page 1
const usersObject = await chat.getUsers(
{
limit: 25,
}
)

// result page 2
const usersObjectPage2 = await chat.getUsers(
{
limit: 25,
page: { next: usersObject.page.next }
}
)

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.

const users = await chat.getUsers(
{
filter: "status=='deleted'"
}
)
Last updated on