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(
string filter = "",
string sort = "",
int limit = 0,
Page page = null
)

Input

ParameterTypeRequiredDefaultDescription
filterstringNoempty stringExpression used to filter the results. Returns only these memberships whose properties satisfy the given expression. The filter language is defined here.
sortstringNoempty stringKey-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.
limitintNo0Number of objects to return in response.
pagePageNonullObject used for pagination to define which previous or next result page you want to fetch.

Output

TypeDescription
ChannelsResponseWrapperAn object containing the filtered, sorted, and paginated list of channels.

Basic usage

Fetch all existing channel IDs.

// fetch all channels
var channels = chat.GetChannels();

// print all channel IDs
foreach (var channel in channels)
{
Console.WriteLine(channel.Id);
}

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.

// fetch the initial 25 channels
var channelsWrapper = chat.GetChannels(limit: 25);

Console.WriteLine("Initial 25 channels:");
foreach (var channel in channelsWrapper.Channels)
{
Console.WriteLine($"Id: {channel.Id}");
}

// fetch the next set of channels using the page object from returned wrapper
var nextChannels = chat.GetChannels(limit: 25, page: channelsWrapper.Page);

Console.WriteLine("\nNext set of channels:");
foreach (var channel in nextChannels)
{
show all 18 lines

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 under the isDeleted parameter.

// define the filter to get archived channels
string filter = "isDeleted = true";

// fetch archived channels
var archivedChannels = chat.GetChannels(filter: filter);

Console.WriteLine("Archived channels:");
foreach (var channel in archivedChannels.Channels)
{
Console.WriteLine($"Id: {channel.Id}");
}
Last updated on