I have a slack application and I have authenticated using this application. When I list all the channels, some of the private channels are not listed. Do we need the access token of workspace admin to list all the private and public channels?
3 Answers
Stumbled across this question when Googling for a similar issue in a large org - I was getting the public channels, but not all of them were showing.
Turns out Slack has a default limit of returning 100 channels. To bypass this, simply pass a limit: 9999
parameter, eg:
app.client.conversations.list({
token: process.env.SLACK_BOT_TOKEN,
limit: 9999
}).then((res: any) => {...})
See also: conversations.list API
-
The Slack API for limit is super confusing. The limit includes archived channels. So if you for instance do a
limit: 50
withexclude_archived: 1
you won't necessarily get 50 channels back, in my case I was getting 16– kabalMar 5, 2021 at 11:43 -
Plus, private channels (or groups) are included AFTER the public channels, so if you have more than 50 public channels (archived or not), you will never see any groups/private channels even if you request them.– PhilAug 17, 2022 at 14:02
-
For reference, here's a link to the Slack Web API docs on rate limiting: slack.dev/node-slack-sdk/web-api#rate-limits Jun 12 at 21:32
Here is how Slack's security architecture works, which explains why you don't get all private channels with conversations.list
.
A user only can only see private channel he is a member of. That includes users with admins and owner role, so even the creator of a workspace does not see private channels he is not invited to.
There are two types of tokens:
- User token inherit the access rights from the user who installs the Slack app. So if you installed a Slack app it can only see the private channels that you are a member of.
- Its a bit different with bot token. With a bot token the app can only see private channel the bot user is a member of.
There are two workarounds to get access to all channels:
Generic user
Ensure a the generic user (e.g. slackadmin
) is a member of all private channels. Then using his access token a Slack app also has access to all those private channels. This is an organizational solution.
Collect all user tokens
Collect the tokens of all users on your workspace and then use those tokens to access all conversations incl. private channels their are a member of. This can be achieved by asking every user to install your Slack app once (via standard OAuth "Add to Slack" process), which is called a configuration in Slack terms.
response = client.conversations_list(types="public_channel, private_channel")