---
source_url: https://www.pubnub.com/docs/sdks/kotlin/entities/channel-metadata
title: ChannelMetadata Entity
updated_at: 2026-06-05T11:12:27.602Z
sdk_name: PubNub Kotlin SDK
sdk_version: 13.4.0
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# ChannelMetadata Entity

PubNub Kotlin SDK, use the latest version: 13.4.0

Install:

```bash
Add PubNub dependency to your build@13.4.0
```

As of version 9.0.0, the Kotlin software development kit (SDK) supports entities. Entities are SDK objects that bundle operations for a specific resource type and simplify working with PubNub application programming interfaces (APIs).

Use entities to perform common tasks without manually wiring requests. Some PubNub APIs are exposed via entities. Other operations remain available on the `pubnub` object.

## Create ChannelMetadata

Use this factory method to return a local `ChannelMetadata` entity for a single channel metadata object. A `ChannelMetadata` entity centralizes operations related to App Context channel metadata.

```kotlin
pubnub.channelMetadata(id: String): ChannelMetadata
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| id | String | Yes |  | Identifier of the [channel metadata](https://www.pubnub.com/docs/general/metadata/channel-metadata) for which to create the entity. |

#### Sample code

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```kotlin
import com.pubnub.api.PubNub
import com.pubnub.api.UserId
import com.pubnub.api.v2.PNConfiguration
import com.pubnub.api.v2.entities.ChannelMetadata

fun main() {
    println("PubNub ChannelMetadata Entity Example")
    println("===================================")

    // 1. Configure PubNub
    val userId = UserId("channel-metadata-entity-demo-user")
    val config = PNConfiguration.builder(userId, "demo").apply {
        publishKey = "demo"
        subscribeKey = "demo"
    }.build()

    // 2. Create PubNub instance
    val pubnub = PubNub.create(config)

    // 3. Create a Channel Metadata entity
    val channelMetadataName = "team-chat"
    val channelMetadata: ChannelMetadata = pubnub.channelMetadata(channelMetadataName)
    println("Created ChannelMetadata entity for: $channelMetadataName")
    channelMetadata.id

    // 4. Set channel metadata
    println("\nSetting channel metadata...")
    pubnub.setChannelMetadata(
        channel = channelMetadataName,
        name = "Team Chat",
        description = "Internal team communication channel",
        includeCustom = true,
        custom = mapOf(
            "type" to "private",
            "category" to "internal",
            "maxUsers" to 50
        )
    ).async { result ->
        result.onSuccess { response ->
            println("SUCCESS: Channel metadata set")
            println("Channel ID: ${response.data?.id}")
            println("Name: ${response.data?.name}")
            println("Description: ${response.data?.description}")
            println("Custom: ${response.data?.custom}")
        }.onFailure { exception ->
            println("ERROR: Failed to set channel metadata")
            println("Error details: ${exception.message}")
        }
    }

    // 5. Define a subscription to the channel metadata
    val channelMetadataSubscription = channelMetadata.subscription()
    channelMetadataSubscription.onMessage = { result ->
        println("\nReceived message on channel metadata subscription: ${result.message.asString}")
    }

    channelMetadataSubscription.subscribe()
    Thread.sleep(2000)

    // 6. Publish a message to the channel
    pubnub.publish(channelMetadataName, "Some message").sync()

    // 7. Wait for operation to complete
    Thread.sleep(2000)

    // 8. Clean up
    pubnub.destroy()
    println("\nPubNub connection closed")
}
```

## Available operations

The `ChannelMetadata` entity provides operations for PubNub App Context [channel metadata](https://www.pubnub.com/docs/general/metadata/channel-metadata).

| Operation (click for more information) | Description |
| --- | --- |
| [subscription(subscriptionOptions)](https://www.pubnub.com/docs/sdks/kotlin/api-reference/publish-and-subscribe#subscribe) | Returns a local channel metadata [subscription object](https://www.pubnub.com/docs/general/channels/subscribe#subscription-types) with [optional parameters](https://www.pubnub.com/docs/general/channels/subscribe#subscription-options). You can then subscribe to receive real-time updates for that channel metadata. |