4

I'm trying to obtain a list of private channels in Slack (on a per-user basis is fine), but I'm having trouble seeing this information. I installed my application into the workspace in Slack originally and got an OAuth token in the form xoxp-4............

App OAuth token

When I try to use the slack API (node SDK) then I only get the publicly listed channels.

await new WebClient(`xoxp-4.....`)
    .conversations       
    .list({ exclude_archived: true })
).channels

I get the same if I try using the Slack API tester to grab a channel list.

User OAuth token
I've followed the OAuth 2.0 process to obtain a token for a given user (myself). I think I've done all this correctly (here's a response):

{
        ok: true,
        access_token: 'xoxp-4.........',
        scope: 'identify,bot,commands,channels:history,groups:history,im:history,mpim:history,channels:read,emoji:read,groups:read,im:read,search:read,team:read,users:read,users:read.email,usergroups:read,users.profile:read,chat:write:user,chat:write:bot,links:read',
        user_id: 'UD......',
        team_name: '............',
        team_id: '.......',
        scopes: ['identify',
            'bot',
            'commands',
            'channels:history',
            'groups:history',
            'im:history',
            'mpim:history',
            'channels:read',
            'emoji:read',
            'groups:read',
            'im:read',
            'search:read',
            'team:read',
            'users:read',
            'users:read.email',
            'usergroups:read',
            'users.profile:read',
            'chat:write:user',
            'chat:write:bot',
            'links:read'
        ]
    }

Interestingly I discovered this provides me with exactly the same OAuth token if I goto the application management (I assume because it was me who installed the app to the workspace).

Obviously, because it's the same token, I don't get permissions to see the private channels still, even though as far as I'm aware I should be able to do everything I can do as a user?

Can anyone point me to what I might be missing?

Sayed Mohd Ali
  • 2,156
  • 3
  • 12
  • 28
Ian
  • 33,605
  • 26
  • 118
  • 198
  • 1
    I had a similar issue, afarid i can't find the link for the exact solution. I think it was something to do with having to use legacy tokens to get access. https://api.slack.com/custom-integrations/legacy-tokens I was using python not node though, and this was last year so things may have changed. – Emile Feb 18 '19 at 13:48
  • @Emile I just tried a token from the legacy-tokens page and with the `channels.list` api function it didn't seem to make any different unfortunately. – Ian Feb 18 '19 at 13:51
  • I realised just now as well that i was downloading from desktop so not quite the same scenario as you. – Emile Feb 18 '19 at 13:53

1 Answers1

8

The reason why you do not get the private channels is that you are not requesting them.

The conversations.list method will return public channels by default only. To also get private channels you need set the parameter types accordingly. e.g. types = public_channel,private_channel.

Similar with calling channels.list. Channels.list will only return public channels. If you want to get the private channels you need to call groups.list. (note that private channels are called groups in the API for historical reasons).

In general I would recommend using conversations.list, which is more powerful and the recommended approach to get all types of conversations.

Erik Kalkoken
  • 30,467
  • 8
  • 79
  • 114
  • 1
    Thanks again Eric - `conversations.list` is actually what I'm using for history (but not for the channel list for some reason). I'll switch it over and accept once I confirm it works. – Ian Feb 18 '19 at 17:21
  • 1
    Happy to help. I guess you might also be interested in getting all private channels of a workspace. If so check out this link for an answer: https://stackoverflow.com/questions/37690761/get-a-list-of-all-private-channels-with-slack-api – Erik Kalkoken Feb 18 '19 at 17:25
  • 1
    Yeah, I've already seen your answer there actually since posting this. It's the approach I'm using actually :) – Ian Feb 18 '19 at 20:39
  • 3
    Actually types=private_channel doesn't return the list of private channels. – Taron Mehrabyan Feb 19 '21 at 18:03
  • 1
    @TaronMehrabyan it sure does – Erik Kalkoken Feb 19 '21 at 18:26
  • It used to return all of them but now it only returns some of the private channels, even though channel name and users hasn't changed – Elliptica Oct 13 '22 at 14:11
  • similar issue: "public_channel,private_channel" returns less items than "public_channel" only – eric f. Jan 30 '23 at 01:01
  • @ErikKalkoken, can I fetch private channels using xoxb token? – Drashti Kheni Mar 27 '23 at 01:00