Warning: You are viewing an old version (1.1) of this documentation. We recommend you view the latest version 1.2.
REST Client Library API

Channel Status

Overview

The Channel Status API is part of the Channel Metadata API, and provides the capability to access information about channels via our REST endpoint. The information includes the current state of a channel, or its current occupancy. This data can be accessed as follows:

At present, REST requests for lifecycle events will not count towards your message limit. If you are making use of Integrations however, then each message sent through Integrations will count towards your message limits.

Note that it is also possible to use the realtime endpoint to subscribe to channel lifecycle events (such as channels being created or closed) and occupancy events for any active channels (such as the counts of publishers, subscribers or presence members as they are added or removed).

In addition, note that since the metadata of various channels is prone to change very frequently, unless you have a special use case within your app, we recommend you to subscribe to the realtime events via the Channel Metadata API rather than poll for updates via REST, as this is inefficient and data is still likely to become stale as soon as you have received it.

Metachannels

Metachannels are a namespace of channels which all start with the [meta] qualifier, uniquely identifying them from regular channels. An example of a metachannel would be [meta]channel.lifecycle.

There are a number of metachannels available, which are:

[meta]log
This metachannel is used to broadcast log messages (usually error messages) for events that occur within the application’s context
[meta]channel.lifecycle
This metachannel carries messages about channel lifecycle and metadata
[meta]connection.lifecycle
This metachannel carries messages about the lifecycle of realtime connections

All of the metadata associated with an app or a channel is available on one of these metachannels only.

Permissions

A regular Ably key has a capability which lists accessible resources and, for any given resource, a set of permitted operations. The wildcard resource ‘*’ will match any regular channel name.

In order to grant permission to a user to access a metachannel, however, the resource name(s) in the capability must include the [meta] qualifier explicitly. If you are using an API Key, you can set up capabilities in your dashboard. If you are making use of tokens, you specify it within the token. The following are examples of capabilities that will validly permit access to a metachannel:

A capability allowing subscription to all metachannels:

{"[meta]*":["subscribe"]}

The above will allow for the key to subscribe to any meta channel. The wildcard * indicates anything can follow the [meta] claim, so an example of a valid channel would be [meta]log. However, this capability will not allow for any other actions to be performed on the metachannels, nor will it allow the key to do anything with any non-metachannels.

A capability allowing all permissible actions on all metachannels and all regular channels:

{
  "[meta]*":["*"],
  "*":["*"]
}

The above permission provides two capabilities: the ability to perform any action on any metachannel (such as [meta]log) with "[meta]*":["*"], and the ability to perform any action on any channel (such as another:channel) with "*":["*"]. However, you are never able to publish or be present in a metachannel, thus this permission in effect would result in an actual permission excluding publish and presence capabilities in [meta] channels due to the intersecting capabilities.

If [meta] is not specified in the permissions, you will be unable to access the metachannels however. An example of this would be the following:

{"*":["*"]}

Although the above provides all capabilities in all regular channels, without a [meta] permission being explicitly specified, you will be unable to perform any actions on a [meta] channel.

Requesting Channel Status

Through the REST library, it is possible to not only check a channel’s status and occupancy data, but it is also possible to enumerate all channels that are currently active within an app.

Channel lifecycle status

This returns a ChannelDetails for the given channel, indicating global occupancy. A side-effect of this request, in the current version of this API, is that it will cause the channel in question to become activated; therefore it is primarily intended to be used in conjunction with the enumeration API or in situations where the application has another means to know whether or not a given channel is active.

Example request:

curl https://rest.ably.io/channels/<channelId> \
 -u "xVLyHw.0cALlg:derlO51V-Q8OvabUr8zAakOPSm3g-3d8wALqx_EqBYI"

The credentials presented with the request must include the channel-metadata permission for the channel in question.

Client libraries currently do not support this API, but it is usable via the generic request API.

Channel enumeration

This enumerates all active channels in the application. This is a paginated API following the same API conventions as other paginated APIs in the Ably REST library.

Example request:

curl https://rest.ably.io/channels \
 -u "xVLyHw.0cALlg:derlO51V-Q8OvabUr8zAakOPSm3g-3d8wALqx_EqBYI"

This will return either a list of channel names, or a ChannelDetails object depending on what options you’ve specified.

The following parameters are supported:

limit
100 optionally specifies the maximum number of results to return. A limit greater than 1000 is unsupported
Type: integer
prefix
optionally limits the query to only those channels whose name starts with the given prefix
Type: string
by
value optionally specifies whether to return just channel names (by=id) or ChannelDetails (by=value)

The credentials presented with the request must include the channel-metadata permission for the wildcard resource '*'.

Client libraries currently do not provide a dedicated API to enumerate channels, but make this available using the request method. When using this, you can simply iterate through the PaginatedResults to enumerate through the results.

Enumeration is possible of all channels in an app, by repeated calls to the API, following the next relative link on each successive call, until there is no next relative link. However, the state of the app and the cluster itself can change during that enumeration. This API therefore has the following limitations:

  • channels that become active, or become inactive, between the first and last request in the sequence, might or might not appear in the result. The API guarantees that if a channel is continuously active from the time that the first request is made until the time that the last request completes, then it is guaranteed to be present in the result. Similarly, if a channel is continuously inactive between those times then it is guaranteed not to be present in the result;
  • cluster state changes, in this first release of this API, may cause a pagination sequence to become invalid, in which case the request will respond with an error with code 40011. In this case, to get a complete result, it is necessary to start the enumeration again from the beginning. Other API options to deal with this possibility will be provided in later versions of this API. Enumerations that are satisfiable in the first response page do not have this issue.

Use cases

Having access to channel metadata can provide numerous benefits. In a scenario where the number of subscribers of a channel goes well beyond a hundred, usage of other options such as presence becomes less effective leading to an unexpected n-squared problem if all of the clients are subscribed to presence. You could instead make use of our channel metadata to check the number of active subscribers.

Equally, you may want to publish your data only if there is a subscriber for that data. The channel lifecycle events can notify you when a channel is opened, becomes active, or is no longer active thus giving your publisher clients an opportunity to know when the last subscriber leaves the channel.

If you need to be able to query channel metadata at any point, you can make use of the Channel Status API to inspect the state of individual channels, or enumerate all active channels in an app.

Tutorials

If you wish to see an example of how to use channel metadata, you can check out our Channel Lifecycle Events tutorial, Channel Occupancy Events tutorial, and the Channel Enumeration tutorial.

API Reference

View the Channel Status API Reference.


Need help?

If you need any help with your implementation or if you have encountered any problems, do get in touch. You can also quickly find answers from our knowledge base, and blog.