Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

slack api to find existing channel

I am playing with slack apis to create an integration. I am able to sucessfully create a slack channel using

 this.http.post(slackApiHost + '/channels.create', payload, {headers: headers})
            .subscribe(
                res => {
                    console.log(res);
                    resolve(res)
                },
                err => {
                    console.log('error:' + err)
                }
                )
        })

the payload looks like

var payload = {
        "name" : channelName
    };

So, it will fail with name_taken if the channel already exists. which is great. However, I need to find the channel id of the existing channel so that i can then use it for my purpose. how do i go about it?

like image 631
Vik Avatar asked Apr 30 '18 18:04

Vik


People also ask

Does Slack have a REST API?

The Web API is a collection of HTTP RPC-style methods, all with URLs in the form https://slack.com/api/METHOD_FAMILY.method . While it's not a REST API, those familiar with REST should be at home with its foundations in HTTP. Use HTTPS, SSL, and TLS v1. 2 or above when calling all methods.

What can you do with Slack API?

Slack's API gives access for developers to create custom apps, workflows, and share data two-way. Slack says its APIs are available for querying information from and enacting change in a Slack workspace.


1 Answers

To get a list of all existing channel you can use conversations.list. This is the most flexible approach and allows you to retrieve any type of channel if you so choose.

If you are looking for a channel by a specific name you will need to first retrieve the list of all channels and then run your own name matching against the full list. An API method which allows you to directly search for a channel by name does not exist.

Note that if you are looking for private channels this method will only retrieve channels that you (the installer of your Slack app / your bot user) has been invited to.

like image 113
Erik Kalkoken Avatar answered Sep 24 '22 07:09

Erik Kalkoken