Channel metadata

Clients can optionally store channel metadata such as a channel name and description. You can also use a custom field to store additional data. Some examples of custom data include a channel's type, purpose, or owner.

Refer to Channel Metadata to learn more about working with channel metadata.

Set channel metadata

Here is a simple example of adding metadata to a channel:

pubnub.objects.setChannelMetadata({
channel: "my_channel",
data: {
name: "main channel",
description: "This channel is for company wide chatter.",
custom: {
"owner": "johndoe_1"
}
}
});

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.

pubnub.objects.getChannelMetadata({
channel: "my_channel"
});

Channel events

PubNub generates channel metadata events when a user metadata is set or deleted. Clients can add Objects Listeners to receive these events.

EventDescriptionPublish location
Channel Metadata SetChannel metadata is set or updated.These events are published on {channel}.
Channel Metadata DeletedChannel metadata is deleted.These events are published on {channel}.

Channel metadata set:

{
"channel":"ch-1",
"message":{
"event":"set",
"type":"channel",
"data":{
"id":"ch-1",
"name":"main channel",
"description":"A meeting room for the team",
"updated":"2020-02-20T23:11:20.893755"
}
},
"subscription":null,
"timetoken":"15119446002445794"
}

Channel metadata removed:

{
"channel":"ch-1",
"message":{
"event":"deleted",
"type":"channel",
"data":{
"id":"ch-1",
"name":"main channel",
"description":"A meeting room for the team",
"updated":"2020-02-20T23:11:20.893755"
}
},
"subscription":null,
"timetoken":"15119446002445794"
}
Last updated on