On this page

List all users

getUsers() returns a paginated list of all users with their metadata.

note

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

icon

Under the hood


This method takes the following parameters:

1chat.getUsers({
2 filter?: string,
3 sort?: object,
4 limit?: number,
5 page?: {
6 next?: string,
7 prev?: string,
8 }
9}): Promise<{
10 users: User[],
11 page: {
12 next: string,
13 prev: string,
14 },
15 total: number,
show all 16 lines

Input

* required
ParameterDescription
filter
Type: string
Default:
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
Type: object
Default:
n/a
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
Type: number
Default:
100
Number of objects to return in response. The default (and maximum) value is 100.
page
Type: object
Default:
n/a
Object used for pagination to define which previous or next result page you want to fetch.
 → next
Type: string
Default:
n/a
Random 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.
 → prev
Type: string
Default:
n/a
Random 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

ParameterDescription
Promise<>
Type: object
Returned object containing three fields: users, page, and total.
 → users
Type: User[]
List of all matching users.
 → page
Type: object
String that lets you either fetch the next (next) or previous (prev) result page.
   → next
Type: string
Random 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.
   → prev
Type: string
Random 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.
 → total
Type: number
Total number of User objects matching the request query.

Sample code

Fetch all existing user IDs.

1// reference the "chat" object and invoke the "getUsers()" method
2const 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.

1// result page 1
2const usersObject = await chat.getUsers(
3 {
4 limit: 25,
5 }
6)
7
8// result page 2
9const usersObjectPage2 = await chat.getUsers(
10 {
11 limit: 25,
12 page: { next: usersObject.page.next }
13 }
14)

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.

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