# Chat Channel Migration Resource

A **Channel** is a Programmable Chat object that is equivalent to a **Conversation** in the Conversations API.

Please see the [Conversation Resource](/docs/conversations/api/conversation-resource) for Conversations that are already available to your Conversations application.

Only 'private' type **Channels** are automatically migrated to Conversations. For 'public' type **Channels**, please use this API to migrate them to 'private' type.

## API Base URL

```bash
https://chat.twilio.com/v3

```

There is only one API endpoint on the v3 Chat API:

```bash
POST /Services/ISxx/Channels/CHxx

```

## Channel Properties

```json
{"type":"object","refName":"chat.v3.channel","modelName":"chat_v3_channel","properties":{"sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^CH[0-9a-fA-F]{32}$","nullable":true,"description":"The unique string that we created to identify the Channel resource."},"account_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^AC[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the [Account](/docs/iam/api/account) that created the Channel resource."},"service_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^IS[0-9a-fA-F]{32}$","nullable":true,"description":"The SID of the [Service](/docs/chat/rest/service-resource) the Channel resource is associated with."},"friendly_name":{"type":"string","nullable":true,"description":"The string that you assigned to describe the resource.","x-twilio":{"pii":{"handling":"standard","deleteSla":30}}},"unique_name":{"type":"string","nullable":true,"description":"An application-defined string that uniquely identifies the resource. It can be used to address the resource in place of the resource's `sid` in the URL.","x-twilio":{"pii":{"handling":"standard","deleteSla":30}}},"attributes":{"type":"string","nullable":true,"description":"The JSON string that stores application-specific data. If attributes have not been set, `{}` is returned.","x-twilio":{"pii":{"handling":"sensitive","deleteSla":30}}},"type":{"type":"string","enum":["public","private"],"description":"The visibility of the channel. Can be: `public` or `private`.","refName":"channel_enum_channel_type","modelName":"channel_enum_channel_type"},"date_created":{"type":"string","format":"date-time","nullable":true,"description":"The date and time in GMT when the resource was created specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."},"date_updated":{"type":"string","format":"date-time","nullable":true,"description":"The date and time in GMT when the resource was last updated specified in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format."},"created_by":{"type":"string","nullable":true,"description":"The `identity` of the User that created the channel. If the Channel was created by using the API, the value is `system`.","x-twilio":{"pii":{"handling":"standard","deleteSla":30}}},"members_count":{"type":"integer","default":0,"description":"The number of Members in the Channel."},"messages_count":{"type":"integer","default":0,"description":"The number of Messages that have been passed in the Channel."},"messaging_service_sid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^MG[0-9a-fA-F]{32}$","nullable":true,"description":"The unique ID of the [Messaging Service](/docs/messaging/api/service-resource) this channel belongs to."},"url":{"type":"string","format":"uri","nullable":true,"description":"The absolute URL of the Channel resource."}}}
```

## Update Channel Type

`POST https://chat.twilio.com/v3/Services/{ServiceSid}/Channels/{Sid}`

Use this API to change a Channel's type from `public` to `private`. This makes it available in Conversations.

> \[!NOTE]
>
> Read [here](/docs/conversations/migrating-chat-conversations#conversations-is-multichannel) to determine if you need to include a Messaging Service SID in your request.

### Headers

```json
[{"name":"X-Twilio-Webhook-Enabled","in":"header","description":"The X-Twilio-Webhook-Enabled HTTP request header","schema":{"type":"string","enum":["true","false"],"refName":"channel_enum_webhook_enabled_type","modelName":"channel_enum_webhook_enabled_type"}}]
```

### Path parameters

```json
[{"name":"ServiceSid","in":"path","description":"The unique SID identifier of the Service.","schema":{"type":"string","minLength":34,"maxLength":34,"pattern":"^IS[0-9a-fA-F]{32}$"},"required":true},{"name":"Sid","in":"path","description":"A 34 character string that uniquely identifies this Channel.","schema":{"type":"string"},"required":true}]
```

### Request body parameters

```json
{"schema":{"type":"object","title":"UpdateChannelRequest","properties":{"Type":{"type":"string","enum":["public","private"],"description":"The visibility of the channel. Can be: `public` or `private`.","refName":"channel_enum_channel_type","modelName":"channel_enum_channel_type"},"MessagingServiceSid":{"type":"string","minLength":34,"maxLength":34,"pattern":"^MG[0-9a-fA-F]{32}$","description":"The unique ID of the [Messaging Service](/docs/messaging/api/service-resource) this channel belongs to."}}},"examples":{"update":{"value":{"lang":"json","value":"{\n  \"Type\": \"private\",\n  \"MessagingServiceSid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n}","meta":"","code":"{\n  \"Type\": \"private\",\n  \"MessagingServiceSid\": \"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"\n}","tokens":[["{","#C9D1D9"],"\n  ",["\"Type\"","#7EE787"],[":","#C9D1D9"]," ",["\"private\"","#A5D6FF"],[",","#C9D1D9"],"\n  ",["\"MessagingServiceSid\"","#7EE787"],[":","#C9D1D9"]," ",["\"MGaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"","#A5D6FF"],"\n",["}","#C9D1D9"]],"annotations":[],"themeName":"github-dark","style":{"color":"#c9d1d9","background":"#0d1117"}}}},"encodingType":"application/x-www-form-urlencoded","conditionalParameterMap":{}}
```

Migrate public Channel to Conversations

```js
// Download the helper library from https://www.twilio.com/docs/node/install
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = twilio(accountSid, authToken);

async function updateChannel() {
  const channel = await client.chat.v3
    .channels("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "Sid")
    .update({
      messagingServiceSid: "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
      type: "private",
    });

  console.log(channel.sid);
}

updateChannel();
```

```python
# Download the helper library from https://www.twilio.com/docs/python/install
import os
from twilio.rest import Client

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

channel = client.chat.v3.channels(
    "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "Sid"
).update(
    type="private", messaging_service_sid="MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
)

print(channel.sid)
```

```csharp
// Install the C# / .NET helper library from twilio.com/docs/csharp/install

using System;
using Twilio;
using Twilio.Rest.Chat.V3;
using System.Threading.Tasks;

class Program {
    public static async Task Main(string[] args) {
        // Find your Account SID and Auth Token at twilio.com/console
        // and set the environment variables. See http://twil.io/secure
        string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID");
        string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN");

        TwilioClient.Init(accountSid, authToken);

        var channel = await ChannelResource.UpdateAsync(
            type: ChannelResource.ChannelTypeEnum.Private,
            messagingServiceSid: "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
            pathServiceSid: "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
            pathSid: "Sid");

        Console.WriteLine(channel.Sid);
    }
}
```

```java
// Install the Java helper library from twilio.com/docs/java/install

import com.twilio.Twilio;
import com.twilio.rest.chat.v3.Channel;

public class Example {
    // Find your Account SID and Auth Token at twilio.com/console
    // and set the environment variables. See http://twil.io/secure
    public static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID");
    public static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN");

    public static void main(String[] args) {
        Twilio.init(ACCOUNT_SID, AUTH_TOKEN);
        Channel channel = Channel.updater("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "Sid")
                              .setType(Channel.ChannelType.PRIVATE)
                              .setMessagingServiceSid("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
                              .update();

        System.out.println(channel.getSid());
    }
}
```

```go
// Download the helper library from https://www.twilio.com/docs/go/install
package main

import (
	"fmt"
	"github.com/twilio/twilio-go"
	chat "github.com/twilio/twilio-go/rest/chat/v3"
	"os"
)

func main() {
	// Find your Account SID and Auth Token at twilio.com/console
	// and set the environment variables. See http://twil.io/secure
	// Make sure TWILIO_ACCOUNT_SID and TWILIO_AUTH_TOKEN exists in your environment
	client := twilio.NewRestClient()

	params := &chat.UpdateChannelParams{}
	params.SetType("private")
	params.SetMessagingServiceSid("MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")

	resp, err := client.ChatV3.UpdateChannel("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
		"Sid",
		params)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		if resp.Sid != nil {
			fmt.Println(*resp.Sid)
		} else {
			fmt.Println(resp.Sid)
		}
	}
}
```

```php
<?php

// Update the path below to your autoload.php,
// see https://getcomposer.org/doc/01-basic-usage.md
require_once "/path/to/vendor/autoload.php";

use Twilio\Rest\Client;

// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
$sid = getenv("TWILIO_ACCOUNT_SID");
$token = getenv("TWILIO_AUTH_TOKEN");
$twilio = new Client($sid, $token);

$channel = $twilio->chat->v3
    ->channels("ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "Sid")
    ->update([
        "type" => "private",
        "messagingServiceSid" => "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
    ]);

print $channel->sid;
```

```ruby
# Download the helper library from https://www.twilio.com/docs/ruby/install
require 'twilio-ruby'

# Find your Account SID and Auth Token at twilio.com/console
# and set the environment variables. See http://twil.io/secure
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
@client = Twilio::REST::Client.new(account_sid, auth_token)

channel = @client
          .chat
          .v3
          .channels('ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'Sid')
          .update(
            type: 'private',
            messaging_service_sid: 'MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
          )

puts channel.sid
```

```bash
# Install the twilio-cli from https://twil.io/cli

twilio api:chat:v3:services:channels:update \
   --service-sid ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa \
   --sid Sid \
   --type private \
   --messaging-service-sid MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
```

```bash
curl -X POST "https://chat.twilio.com/v3/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/Sid" \
--data-urlencode "Type=private" \
--data-urlencode "MessagingServiceSid=MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" \
-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
```

```json
{
  "sid": "Sid",
  "account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "service_sid": "ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
  "messaging_service_sid": "MGXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "friendly_name": "friendly_name",
  "unique_name": "unique_name",
  "attributes": "{ \"foo\": \"bar\" }",
  "type": "private",
  "date_created": "2015-12-16T22:18:37Z",
  "date_updated": "2015-12-16T22:18:38Z",
  "created_by": "username",
  "members_count": 0,
  "messages_count": 0,
  "url": "https://chat.twilio.com/v3/Services/ISaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/Channels/CHaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
}
```
