Skip to content

Instantly share code, notes, and snippets.

@umihico
Created Jan 2, 2020
Embed
What would you like to do?
get all slack ids in your slack workspace

python list_all_slack_id.py xoxp-000000000000-abcdef

output will be like

https://slack.com/api/channels.list?token=xoxp-000000000000-abcdef
https://slack.com/api/usergroups.list?token=xoxp-000000000000-abcdef
https://slack.com/api/users.list?token=xoxp-000000000000-abcdef
{'CB0000000': 'general',
 'CB0000000': 'random',
 'UB0000000': 'umihico',
 'USLACKBOT': 'slackbot'}

use grep to filter the output

import requests
import pprint
urls=[
"https://slack.com/api/channels.list",
"https://slack.com/api/usergroups.list",
"https://slack.com/api/users.list",
]
json_keys=[
'channels',
'usergroups',
'members',
]
import sys
token=sys.argv[1]
result={}
for url, key in zip(urls, json_keys):
print(url+"?token="+token)
result.update({d['id']:d['name'] for d in requests.get(url+"?token="+token).json()[key]})
pprint.pprint(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment