Search code examples
slackslack-api

slack - get team URL from webhooks


Is it possible to either get the team URL from a slack webhook or get the team URL from a channel/user ID?

For example, from the hook:

https://hooks.slack.com/service/foobar-hook get the team URL in order to do other things with slack API. The main idea is to minimize code/configuration. You pass the webhooks and you're done, instead of passing the webhook and also de team URL.

And the same for a channel id:

Is it possible from the channel ID HNAs319A get the team URL?


Solution

  • No. Webhook URLs have no relation to the slack URL. They do contain the team ID though.

    Example for team with ID T1234567: https://hooks.slack.com/services/T1234567/XXX/YYY

    Channel IDs are only unique within a team, so its not possible to extract the slack URL from it.

    You can however get the slack URL if you have a valid access token with the API method auth.test. Maybe that helps solve your problem.

    Here is an response example for that method (from the documentation):

    {
        "ok": true,
        "url": "https:\/\/myteam.slack.com\/",
        "team": "My Team",
        "user": "cal",
        "team_id": "T12345",
        "user_id": "U12345"
    }