val channelClient = client.channel("messaging", "general")
channelClient.delete().enqueue { result ->
if (result is Result.Success) {
val channel = result.value
} else {
// Handle Result.Failure
}
}Deleting Channels
You can delete or truncate a channel to remove its contents. To remove only messages while preserving the channel, see Truncate Channel.
Deleting a Channel
You can delete a single Channel using the delete method. This marks the channel as deleted and hides all the messages.
const destroy = await channel.delete();use GetStream\ChatClient;
use GetStream\GeneratedModels as Models;
$client = new ChatClient("{{ api_key }}", "{{ api_secret }}");
$client->deleteChannel("messaging", "general", false);await channel.delete();import Stream Chat
let controller = chatClient.channelController(for: .init(type: .messaging, id: "general"))
controller.deleteChannel { error in
if let error = error {
// handle error
print(error)
}
}Channel->Delete();require 'getstream_ruby'
Models = GetStream::Generated::Models
client.chat.delete_channel("messaging", "general")# Get a channel
channel = client.chat.channel("messaging", "general")
channel.delete()channel := client.Chat().Channel("messaging", "general")
channel.Delete(ctx, &getstream.DeleteChannelRequest{})using GetStream;
using GetStream.Models;
var client = new StreamClient("{{ api_key }}", "{{ api_secret }}");
var chat = new ChatClient(client);
var channelId = "channel-id";
// Soft delete
await chat.DeleteChannelAsync("messaging", channelId);
// Hard delete
await chat.DeleteChannelAsync("messaging", channelId,
new { hard_delete = "true" });// Soft delete channel
await channel.DeleteAsync();// Backend SDK
chat.deleteChannel(channel.getType(), channel.getId(),
DeleteChannelRequest.builder().build()).execute();
// Hard delete
chat.deleteChannel(channel.getType(), channel.getId(),
DeleteChannelRequest.builder().HardDelete(true).build()).execute();If you recreate this channel, it will show up empty. Recovering old messages is not supported. Use the disable method if you want a reversible change.
Deleting Many Channels
You can delete up to 100 channels and optionally all of their messages using this method. This can be a large amount of data to delete, so this endpoint processes asynchronously, meaning responses contain a task ID which can be polled using the getTask endpoint to check status of the deletions. Channels will be soft-deleted immediately so that channels no longer return from queries, but permanently deleting the channel and deleting messages takes longer to process.
By default, messages are soft deleted, which means they are removed from client but are still available via server-side export functions. You can also hard delete messages, which deletes them from everywhere, by setting "hard_delete": true in the request. Messages that have been soft or hard deleted cannot be recovered.
This is currently supported on the following SDK versions (or higher):
- Javascript 4.3.0, Python 3.14.0, Ruby 2.12.0, PHP 2.6.0, Go 3.13.0, Java 1.4.0, Unity 2.0.0 and .NET 0.22.0
// client-side soft delete
const response = await client.deleteChannels([cid1, cid2]);
// client-side hard delete
const response = await client.deleteChannels([cid1, cid2], {
hard_delete: true,
});
const result = response.result; // holds deletion result
// server-side soft delete
const response = await serverClient.deleteChannels([cid1, cid2]);
// server-side hard delete
const response = await serverClient.deleteChannels([cid1, cid2], {
hard_delete: true,
});
const result = await serverClient.getTask(response.task_id);
if (result["status"] === "completed") {
// success!
}// soft deletion
resp, _ := client.Chat().DeleteChannels(ctx, &getstream.DeleteChannelsRequest{
Cids: []string{cid1, cid2},
})
// hard deletion
resp, _ = client.Chat().DeleteChannels(ctx, &getstream.DeleteChannelsRequest{
Cids: []string{cid1, cid2},
HardDelete: getstream.PtrTo(true),
})
taskResp, err := client.GetTask(ctx, *resp.Data.TaskID, &getstream.GetTaskRequest{})
if err != nil {
// handle error
}
if taskResp.Data.Status == "completed" {
// success!
}# soft deletion
response = client.chat.delete_channels(cids=[cid1, cid2])
# hard deletion
response = client.chat.delete_channels(cids=[cid1, cid2], hard_delete=True)
task_response = client.get_task(id=response.data.task_id)
if task_response.data.status == "completed":
# success!
passrequire 'getstream_ruby'
Models = GetStream::Generated::Models
# soft deletion
response = client.chat.delete_channels(Models::DeleteChannelsRequest.new(
cids: [cid1, cid2]
))
# hard deletion
response = client.chat.delete_channels(Models::DeleteChannelsRequest.new(
cids: [cid1, cid2],
hard_delete: true
))
task_response = client.common.get_task(response.task_id)
if task_response.status == 'completed'
# success!
end// soft deletion
$response = $client->deleteChannels(new Models\DeleteChannelsRequest(
cids: ["messaging:channel-1", "messaging:channel-2"],
));
// hard deletion
$response = $client->deleteChannels(new Models\DeleteChannelsRequest(
cids: ["messaging:channel-1", "messaging:channel-2"],
hardDelete: true,
));
$taskResponse = $client->getTask($response->getData()->taskID);// soft deletion
var response = chat.deleteChannels(DeleteChannelsRequest.builder()
.cids(List.of(cid1, cid2))
.build()).execute();
// hard deletion
var response = chat.deleteChannels(DeleteChannelsRequest.builder()
.cids(List.of(cid1, cid2))
.hardDelete(true)
.build()).execute();
var taskResponse = client.getTask(response.getData().getTaskId()).execute();
// "completed".equals(taskResponse.getData().getStatus());using GetStream;
using GetStream.Models;
var client = new StreamClient("{{ api_key }}", "{{ api_secret }}");
var chat = new ChatClient(client);
// Soft deletion
var resp = await chat.DeleteChannelsAsync(new DeleteChannelsRequest
{
Cids = new List<string> { "messaging:channel-1", "messaging:channel-2" },
HardDelete = false
});
// Hard deletion
resp = await chat.DeleteChannelsAsync(new DeleteChannelsRequest
{
Cids = new List<string> { "messaging:channel-1", "messaging:channel-2" },
HardDelete = true
});// Hard delete removes the channel entirely from the database while soft delete removes the from users to see but it's still accessible via server-side SDK as an archive
await Client.DeleteMultipleChannelsAsync(new[] { channel, channel2 }, isHardDelete: true);The deleteChannels response contain a taskID which can be polled using the getTask endpoint to check the status of the deletions.