List all channels

getChannels() returns a paginated list of all existing channels.

By default, this method returns all custom channel metadata without the need to explicitly define that during the call.

Requires App Context

To store data about channels, 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 Channel Metadata option in the App Context configuration in the Admin Portal – this way you can get metadata of all channels without the need to define that in the permissions schema included in the authentication token.

To get a list of all channels a user is a member of, use the getMemberships() method.

Method signature

This method takes the following parameters:

chat.getChannels(
filter: String?,
sort: Collection<PNSortKey<PNKey>> = listOf(),
limit: Int?,
page: PNPage?
): PNFuture<GetChannelsResponse>

Input

ParameterTypeRequiredDefaultDescription
filterStringNon/aExpression used to filter the results. Returns only these channels whose properties satisfy the given expression are returned. The filter language is defined here.
sortCollection<PNSortKey<PNKey>>NolistOf()A collection to specify the sort order. Available options are id, name, and updated. Use asc or desc to specify the sorting direction. For example: listOf(PNSortKey.asc(PNKey.NAME)). Unless specified otherwise, the items are sorted by the last updated date. Defaults to an empty list.
limitIntNo100Number of objects to return in response. The default (and maximum) value is 100.
pagePNPageNon/aObject used for pagination to define which previous or next result page you want to fetch.

Output

TypeDescription
PNFuture<GetChannelsResponse>PNFuture containing a set of channels with pagination information (next, prev, total).

Basic usage

Fetch all existing channel IDs.

chat.getChannels().async { result ->
result.onSuccess {
// handle success
}.onFailure {
// handle failure
}
}

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.

chat.getChannels(limit = 25).async { result ->
result.onSuccess { channelsObject: GetChannelsResponse ->
chat.getChannels(limit = 25, page = channelsObject.next)
.async { result2 ->
result2.onSuccess { channelsObjectPage2 -> ... }
.onFailure { ... }
}
}.onFailure { ... }
}

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.

chat.getChannels(filter = "status=='deleted'").async { result ->
result.onSuccess {
// handle success
}.onFailure {
// handle failure
}
}
Last updated on