This is more like a question than an issue.
Sometimes there is no way for a bot to create a new channel by NAME because it is already created, and no way to get the Channel without fetching all channels list and iterating through most of them to get the channel you want.
It is not really a bug
slackclient version: 1.2.1
python version: 3.7.3
OS version(s): Any
api_key = 'key...'
client = SlackClient(api_key)
result = client.api_call("channels.create", name='test')
if not result['ok'] and result['error'] == 'name_taken':
... some way to find the channel ID
the behavior seems fine, though it would've been better if it would like something like this
{'ok': False, 'error': 'name_taken', channel: {...}, 'headers': {...}}
{'ok': False, 'error': 'name_taken', 'headers': {...}}
None
Hey @gothraven ,
Thanks for this. Completely get where you're coming from. However this is more to do with the information our API returns for the *.create endpoints. You may be able to do similar yourself by calling the create api call and if you get that error, you run *.list and iterate over the results until you find a matching channel name. It would depend on pagination too however.
The one thing to be aware of, the channels.* and groups.* endpoints are being retired in place of conversations.*. This endpoint allows you to check both private and public channels provided you have access to them.
I will mention to our product managers that you'd like this to happen but I'm afraid at the moment, I think this would be out of scope for the SDK itself.
Thanks for your feedback and information however!
It makes no sense to iterate over more than 7K channels to get the right one, fetching all channels, I think there can be a better way to filter the channels.list based on name or something ?
I have hit this issue as well - the API is definitely deficient in this respect. As @gothraven points out there should be a way to search for channel(s) by name.
Same issue here. Is there any update or still need to iterate?
Also just ran into this. Making loads of api calls and iterating over thousands of channels just to find the ID that matches the name I have seems... inefficient.
Most helpful comment
Also just ran into this. Making loads of api calls and iterating over thousands of channels just to find the ID that matches the name I have seems... inefficient.