Search code examples
slackslack-api

Slack API to get available workspaces


I have an slack app. Is there an API for listing all the workspaces to which the application has access?


Solution

  • No. All API methods require you to prove a token, which is always bound to a single workspace.

    But - you can get that information in another way. Here is how:

    Make sure you store all tokens your app received during the Oauth installation process (you will need to do that for most apps anyhow so you can use any workspace related API method later in your app)

    Call the API method auth.test for each of your tokens to see if its still valid. Luckily there is no rate limiting on this method and you don't need any special scopes, so you can quickly check the status of all your tokens.

    Another more elegant approach to using auth.test is to subscribe your app to the app_uninstalled and / or tokens_revoked events. That way your app will be notified when the tokens are no longer valid and can act on it accordingly.