Channel Metadata
Manage channel data with BizOps Workspace
Use BizOps Workspace in the Admin Portal to create, edit, or delete channels and their data. It lists all channels on your app’s keysets.
The App Context service lets you store metadata for channels, channel memberships, channel members, and users.
Channel metadata has built‑in name
and description
fields. You can also add a custom
object with extra attributes your app needs on the PubNub platform.
Illuminate & sensitive data
You can track App Context data in Illuminate for real‑time analytics.
Illuminate uses JSON paths and mapping when you create Business Objects. Avoid PII in custom
fields, such as email addresses, profile URLs, or IP addresses.
Channel metadata
The App Context service emits events when a channel’s metadata is set or deleted. Your app can receive these events in real time and update the UI.
The next sections show what you can do with channel metadata.
Set channel metadata
You can set built‑in and custom metadata by providing key/value pairs.
API limits
To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.
The code below adds the name
, description
, and custom owner
information to the channel my_channel
.
- JavaScript
- Objective-C
- Java
- C#
pubnub.objects.setChannelMetadata({
channel: "my_channel",
data: {
name: "main channel",
description: "This channel is for company wide chatter.",
custom: { "owner": "johndoe_1" }
}
});
self.client.objects().setChannelMetadata(@"my_channel")
.name(@"main channel")
.information(@"This channel is for company wide chatter.")
.custom(@{ @"owner": @"johndoe_1" })
.includeFields(PNChannelCustomField)
.performWithCompletion(^(PNSetChannelMetadataStatus *status) {
if (!status.isError) {
/**
* Channel metadata successfully has been set.
* Channel metadata information available here: status.data.metadata
*/
} else {
/**
* Handle channel metadata update error. Check 'category' property to find out possible
* issue because of which request did fail.
show all 20 linesMap<String, Object> custom = new HashMap<>();
custom.put("owner", "johndoe_1");
pubnub.setChannelMetadata()
.channel("my_channel")
.name("main channel")
.description("This channel is for company wide chatter.")
.custom(custom)
.includeCustom(true)
.async(result -> { /* check result */ });
PNResult<PNSetChannelMetadataResult> setChannelMetadataResponse = await pubnub.SetChannelMetadata()
.Channel("my_channel")
.Name("main channel")
.Description("This channel is for company wide chatter.")
.Custom(new Dictionary<string, object>() { { "owner", "johndoe_1" } })
.IncludeCustom(true)
.ExecuteAsync();
PNSetChannelMetadataResult setChannelMetadataResult = setChannelMetadataResponse.Result;
PNStatus status = setChannelMetadataResponse.Status;
On success, the SDK returns the same metadata object with status 200. It also fires an objects
→ channel
→ set
event for other clients. See Init & Add Listener.
Get channel metadata
Provide the channel ID to get its metadata. You can also include custom metadata in the response. The example below returns all metadata for my_channel
.
- JavaScript
- Objective-C
- Java
- C#
pubnub.objects.getChannelMetadata({
channel: "my_channel"
});
self.client.objects().channelMetadata(@"my_channel")
.includeFields(PNChannelCustomField)
.performWithCompletion(^(PNFetchChannelsMetadataResult *result, PNErrorStatus *status) {
if (!status.isError) {
/**
* Channel metadata successfully fetched.
* Channel metadata information available here: result.data.metadata
*/
} else {
/**
* Handle channel metadata fetch error. Check 'category' property to find out possible
* issue because of which request did fail.
*
* Request can be resent using: [status retry]
*/
show all 17 linespubnub.getChannelMetadata()
.channel("my_channel")
.includeCustom(true)
.async(result -> { /* check result */ });
PNResult<PNGetChannelMetadataResult> getChannelMetadataResponse = await pubnub.GetChannelMetadata()
.Channel("my_channel")
.IncludeCustom(true)
.ExecuteAsync();
PNGetChannelMetadataResult getChannelMetadataResult = getChannelMetadataResponse.Result;
PNStatus status = getChannelMetadataResponse.Status;
On success, the PubNub SDK returns the metadata of the specified channel along with status 200.
Get metadata for all channels
You can get metadata for all channels for the API key. You can choose to include custom metadata. The example below returns all predefined and custom metadata for all channels:
- JavaScript
- Objective-C
- Java
- C#
pubnub.objects.getAllChannelMetadata();
self.client.objects().allChannelsMetadata()
.start(@"<next from previous request>")
.includeFields(PNChannelCustomField)
.performWithCompletion(^(PNFetchAllChannelsMetadataResult *result, PNErrorStatus *status) {
if (!status.isError) {
/**
* Channels metadata successfully fetched.
* Result object has following information:
* result.data.metadata - List of fetched channels metadata.
* result.data.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.
* result.data.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.
* result.data.totalCount - Total number of associated channel metadata.
} else {
/**
* Handle channels metadata fetch error. Check 'category' property to find out possible
show all 21 linespubnub.getAllChannelsMetadata()
.includeCustom(true)
.async(result -> { /* check result */ });
PNResult<PNGetAllChannelMetadataResult> getAllChannelMetadataResponse = await pubnub.GetAllChannelMetadata()
.IncludeCustom(true)
.ExecuteAsync();
PNGetAllChannelMetadataResult getAllChannelMetadataResult = getAllChannelMetadataResponse.Result;
PNStatus status2 = getAllChannelMetadataResponse.Status;
On success, the PubNub SDK returns a paginated list of metadata for all channels.
Remove channel metadata
You can remove all metadata for one channel. The example below removes all metadata for my_channel
.
Cascading deletes
When you enable referential integrity on a keyset in the Admin Portal, deleting a channel also deletes its memberships.
If it’s not enabled, deleting a channel won’t delete related memberships.
- JavaScript
- Objective-C
- Java
- C-Sharp
pubnub.objects.removeChannelMetadata({
channel: "my_channel"
});
self.client.objects().removeChannelMetadata(@"my_channel")
.performWithCompletion(^(PNAcknowledgmentStatus *status) {
if (!status.isError) {
// Channel metadata successfully removed.
} else {
/**
* Handle channel metadata remove error. Check 'category' property to find out possible
* issue because of which request did fail.
*
* Request can be resent using: [status retry]
*/
}
});
pubnub.removeChannelMetadata()
.channel("my_channel")
.async(result -> { /* check result */ });
PNResult<PNRemoveChannelMetadataResult> removeChannelMetadataResponse = await pubnub.RemoveChannelMetadata()
.Channel("my_channel")
.ExecuteAsync();
PNRemoveChannelMetadataResult removeChannelMetadataResult = removeChannelMetadataResponse.Result;
PNStatus status = removeChannelMetadataResponse.Status;
On completion, the PubNub SDK will fire the objects
-> channel
-> delete
event so it can be consumed for other clients (users). Refer to Receive Messages to learn more.