0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Slack で bot を除くメンバー一覧の取得方法

Last updated at Posted at 2021-07-09

プログラム組むのも手間だなーと思い、シェルだけでやってみた。
この3stepで取得可能。

token取得

slack app 作ってtoken取得しておく
slack_token.png

token取得の細かい手順はこちら参考
https://qiita.com/sukebeeeeei/items/7b059f0d8f90183ecb67

ユーザ一覧取得

curlでAPI叩く

curl -X POST -H 'Authorization: Bearer <token>' \
-H 'Content-type: application/json' \
https://slack.com/api/users.list > users_0.json

上記の結果、next_cursor が空じゃない場合は、続けて以下

curl -X POST -H 'Authorization: Bearer <token>' \
-H 'Content-type: application/json' \
https://slack.com/api/users.list\&cursor=<next_cursor> > users_1.json

& の前に \ がいることに注意。
これらで取得した一覧にはbot(slack app)も含まれる。

botを除く

取得できたusersxx.jsonを一つのusers.jsonとしてmergeして jq でfilterする

cat users.json | jq '.members | map(select(.is_bot == false)) | map({id: .id, name: .name})'

結果例

[
  {
    "id": "UXXXXXXXXX01",
    "name": "xxxxx.yyyyy"
  },
  {
    "id": "UXXXXXXXXX02",
    "name": "zzzzz.yyyyy"
  },
・・・
]
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?