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
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 linesInput
filter#- 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#- Key-value pair of a property to sort by, and a sort direction. Available options are
id,name, andupdated. Useascordescto specify the sorting direction, or specifynullto take the default sorting direction (ascending). For example:{name: "asc"}. By default, the items are sorted by the last updated date. limit#- Number of objects to return in response. The default (and maximum) value is
100. page#- Object used for pagination to define which previous or next result page you want to fetch.
- property of page:
next# - 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# - 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
nextparameter is supplied.
Output
Promise<>#- Returned object containing three fields:
channels,page, andtotal. - property of Promise<>:
channels# - List of all matching channels.
- property of Promise<>:
page# - Object that lets you either fetch the next (
next) or previous (prev) result page. - property of page:
next# - 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# - 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
nextparameter is supplied. - property of Promise<>:
total# - Total number of
Channelobjects 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)