List all channels

Get a paginated list of all channels with getChannels(). Custom channel metadata is included by default.

Requires App Context

Enable App Context for your keyset in the Admin Portal.

With Access Manager enabled, uncheck Disallow Get All Channel Metadata in the App Context configuration to retrieve all channel metadata without defining permissions in the authentication token.

To list channels a user belongs to, use getMemberships() instead.

Method signature​

icon

Under the hood


This method takes the following parameters:

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

Input​

filter#
Type: string
Default: no default
Expression used to filter the results. Returns only these channels whose properties satisfy the given expression are returned. The filtering language is defined here.
sort#
Type: object
Default: no default
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: no default
Object used for pagination to define which previous or next result page you want to fetch.
property of page: next#
Type: string
Default: no default
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.
property of page: prev#
Type: string
Default: no default
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​

Promise<>#
Type: object
Returned object containing three fields: channels, page, and total.
property of Promise<>: channels#
Type: Channel[]
List of all matching channels.
property of Promise<>: page#
Type: object
Object that lets you either fetch the next (next) or previous (prev) result page.
property of 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.
property of page: 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.
property of Promise<>: total#
Type: number
Total number of Channel objects matching the request query.

Sample code​

Fetch all existing channel IDs.

1// reference the "chat" object and invoke the "getChannels()" method
2const channels = await chat.getChannels()

Other examples​

Pagination​

Get the number of 25 channels and then specify that you want to fetch the results from the next page using a string previously returned from the PubNub server.

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

Archived channels​

Get all archived channels. This request will return all channels removed with the soft option set to true, whose data is still stored in the App Context storage.

1const channels = await chat.getChannels(
2 {
3 filter: "status=='deleted'"
4 }
5)

Was this page useful?

Last updated on