Skip to content

Instantly share code, notes, and snippets.

@umihico
Created January 2, 2020 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save umihico/ecf57c79f18c7ddeaab8f14f6fbf5e28 to your computer and use it in GitHub Desktop.
Save umihico/ecf57c79f18c7ddeaab8f14f6fbf5e28 to your computer and use it in GitHub Desktop.
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