Channel Metadata
Manage channel data with BizOps Workspace
You can create, edit, or delete channels and their data using BizOps Workspace on Admin Portal that provides a preview of all channels available on your apps' keysets.
The App Context service allows you to persist metadata about channels, channel memberships, channel members, and users. The name
and description
are the predefined properties for channel metadata. Additionally, there is a custom
property that you can use to store any custom attribute about a channel as per your business needs.
Illuminate & sensitive data
You can capture and track your App Context data in Illuminate for real-time decisioning and analytics.
Illuminate captures all data you define with JSON paths and map when creating measures and dimensions for the Business Objects. For this reason, make sure you don’t include any PII data (e-mail address, profile URL, or IP address) in the custom
fields of your App Context mappings.
Channel Metadata
The App Context service emits events when the metadata associated to a particular channel ID is set or deleted. Your application can receive these events in real time and dynamically react to data changes by updating the information visible on the front end of your app, for instance.
In the following sections, we're going to focus on what you can actually do with channels and their metadata.
Set Channel Metadata
You can set any of the predefined or custom channel metadata by providing the desired information as 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 PubNub SDK returns same metadata object along with status 200, it will also the fire objects
-> channel
-> set
event so it can be consumed for other clients (users). Refer to Init & Add Listener section to learn more.
Get Channel Metadata
You can retrieve the metadata of a specific channel by simply providing the channel ID. You can optionally specify whether custom metadata should be included in the response. The code below returns all metadata of the channel with the ID 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 also retrieve metadata for all the channels associated with the API key. You can optionally specify whether custom metadata should be included in the response. The code below returns all predefined and custom metadata of 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 a single channel. The code below removes all metadata of the channel with the ID my_channel
.
Cascading deletes
Enabling referential integrity on your app’s keyset in the Admin Portal ensures that deleting a channel entity automatically deletes any memberships related to this channel. If it's not enabled, deleting a channel does not automatically delete any associated membership objects.
- 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.