Batch channel update

LAST EDIT Feb 19 2021

The updateChannels endpoint allows you to partially update many channels at once. Here a few things to keep in mind

  • It implements a partial update. Existing fields on a channel won't be removed

  • Upsert is supported. So if the channel doesn't exist it is created if you've specified the required fields (type, id and created_by_id)

  • Adding members or member invites is supported

Here's a simple example of how to update/create a channel

1
2
3
4
5
6
7
// update/create a channel 
const channels = [{type: "messaging", id: "abc", "created_by_id": "abc", "color": "green"}] 
client.updateChannels(channels, {upsert: true}) 
 
// update/create a channel with members 
const channels = [{members: ["john", "alice"], type: "messaging", id: "abc", "created_by_id": "abc", "color": "green"}] 
client.updateChannels(channels, {upsert: true})

The endpoint also supports a more advanced syntax for creating members allowing you to send an invite or make someone a moderator

1
2
3
4
// make john a moderator and invite alice to be a regular user 
const members = [{user_id: "john", role: "moderator"}, {user_id: "alice", type: "invite"}] 
const channels = [{members, type: "messaging", id: "abc", "created_by_id": "abc", "color": "green"}] 
client.updateChannels(channels, {upsert: true})

If you need more fine grained control over the update we also support a set/ unset type of syntax. The example below sets the custom field color to green and removes the field favorite_book

1
2
3
// update/create a channel 
const channels = [{set: {color: "green"}, unset: ["favorite_book"]}] 
client.updateChannels(channels, {upsert: false})

There are a few limitations to keep in mind when using this endpoint:

  • Custom data on a channel can't exceed 5KB

  • You can update frozen (boolean), cooldown (integer) and team (string) on a channel but remember to use the right type.

  • Removing members is not supported via this API. If you want to remove a member use the dedicated endpoint for that.

  • The endpoints for updating a single channel allow you to send a message. This is not supported on the batch endpoint

nametypedescriptiondefaultoptional
frozenbooleanprevents non-moderators from writing new messages on this channelfalse
cooldowninteger-
teamstringfor team based permissions associated this channel with a given team. be sure to not make mistakes changing a channel's team.-