Channel Management
Learn to use Slack API calls to manage channels in the workspace.
Let’s look at the following endpoints in this lesson:
conversations.kick
: This endpoint removes a user from a channel.conversations.archive
: This endpoint archives a channel.
Remove a user from a channel
To remove a user from a channel, we access the https://slack.com/api/conversations.kick
endpoint.
Only channel owners and workspace admins can remove users from channels by default. Change the admin settings to allow the application to remove users.
- Click the name of your workspace.
- Open “Workspace settings” in the “Settings & administration” menu.
- Go to the “Permissions” tab.
- Expand the “Channel Management” section.
- Go to the “People who can remove members from public channels” drop-down menu.
- Select “Everyone, except guests,” and press “Save.”
Request parameters
Some important query parameters for the conversations.kick
endpoint are as follows:
Parameter | Type | Category | Description |
| token | required | Authentication tokens carry the required scopes that govern the usage of different Slack applications and APIs. We usually pass these tokens as an HTTP Authorization header or as a POST parameter. |
| string | required | This parameter specifies the channel to which the message will be posted. It can be a public channel, a private group, or an IM channel (direct message). The value for this parameter can either be an encoded ID or a name of a channel. |
| string | required | This is the user ID that is removed. |
Let’s call the conversations.kick
endpoint. Click the “Run” button to remove a user (in this case, yourself) from the specified channel.
import fetch from "node-fetch";const url = "https://slack.com/api/conversations.kick";const headerParameters = {Authorization: "Bearer {{TOKEN}}","Content-Type": "application/json; charset=UTF-8",};const bodyParameters = JSON.stringify({channel: "{{CHANNEL_ID_APP}}",user: "{{USER_ID}}",});const options = {method: "POST",headers: headerParameters,body: bodyParameters,};async function kickUser() {try {const response = await fetch(url, options);printResponse(response);} catch (error) {printError(error);}}kickUser();
Let’s look at the highlighted lines in the code widget shown above:
- Line 3: We specify the
conversations.kick
endpoint. - Lines 10–13: We specify the
channel
and theuser
parameters to remove the user from a channel.
Response fields
A response from this endpoint includes only the ok
property indicating whether the request was successful.
Archive a channel
To archive a channel, we access the https://slack.com/api/conversations.archive
endpoint. We use this endpoint if a channel is no longer needed.
Note: As of now, once a conversation is archived, you can’t use the bot token to unarchive it.
Request parameters
Some important query parameters for the conversations.archive
endpoint are as follows:
Parameter | Type | Category | Description |
| token | required | Authentication tokens carry the required scopes that govern the usage of different Slack applications and APIs. We usually pass these tokens as an HTTP Authorization header or as a POST parameter. |
| string | required | This parameter specifies the channel to which the message will be posted. It can be a public channel, a private group, or an IM channel (direct message). The value for this parameter can either be an encoded ID or a name of a channel. |
Let’s call the conversations.archive
endpoint. Click the “Run” button to archive the channel made by the application. You shouldn’t be able to see the channel in the “Channels” list on Slack.
import fetch from "node-fetch";const url = "https://slack.com/api/conversations.archive";const headerParameters = {Authorization: "Bearer {{TOKEN}}","Content-Type": "application/json; charset=UTF-8",};const bodyParameters = JSON.stringify({channel: "{{CHANNEL_ID_APP}}",});const options = {method: "POST",headers: headerParameters,body: bodyParameters,};async function archiveChannel() {try {const response = await fetch(url, options);printResponse(response);} catch (error) {printError(error);}}archiveChannel();
Let’s look at the highlighted lines in the code widget shown above:
- Line 3: We specify the
conversations.archive
endpoint. - Line 11: We specify the channel that needs to be archived in the parameters.
Response fields
A response from this endpoint includes only the ok
property indicating whether the request was successful.