users.list API概要
機能
Slackのワークスペースに過去も含め所属する/所属したことのあるユーザの一覧を取得するためのAPI
利用方法
endpoint url
https://slack.com/api/users.list
パラメータ
Argument(引数)
token
必須/任意
必須
概要
usersへのアクセス権限を設定したトークン
cursor
任意
開始位置の指定。cursorはSQLのcursorと同じイメージ。defaultは最初のページから。response_metadataに含まれるnext_cursorの一つ前から処理開始
include_locale(注1)
任意
言語指定(多国籍や複数国で一つのチャネルを利用しているときに、言語別にユーザを取得するイメージ)。defaultは指定なし
limit
任意
取得上限数。defalutは指定なし
注1 参考リンク:https://api.slack.com/changelog/2017-09-locale-locale-locale
HTTP method(preferred)
Get
Response
user objectが順不同で返ってくる。実際イメージは以下。
{
"ok": true,
"members": [
{
"id": "W012A3CDE",
"team_id": "T012AB3C4",
"name": "spengler",
"deleted": false,
"color": "9f69e7",
"real_name": "spengler",
"tz": "America/Los_Angeles",
"tz_label": "Pacific Daylight Time",
"tz_offset": -25200,
"profile": {
"avatar_hash": "ge3b51ca72de",
"status_text": "Print is dead",
"status_emoji": ":books:",
"real_name": "Egon Spengler",
"display_name": "spengler",
"real_name_normalized": "Egon Spengler",
"display_name_normalized": "spengler",
"email": "spengler@ghostbusters.example.com",
"image_24": "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
"image_32": "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
"image_48": "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
"image_72": "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
"image_192": "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
"image_512": "https://.../avatar/e3b51ca72dee4ef87916ae2b9240df50.jpg",
"team": "T012AB3C4"
},
"is_admin": true,
"is_owner": false,
"is_primary_owner": false,
"is_restricted": false,
"is_ultra_restricted": false,
"is_bot": false,
"updated": 1502138686,
"is_app_user": false,
"has_2fa": false
},
{
"id": "W07QCRPA4",
"team_id": "T0G9PQBBK",
"name": "glinda",
"deleted": false,
"color": "9f69e7",
"real_name": "Glinda Southgood",
"tz": "America/Los_Angeles",
"tz_label": "Pacific Daylight Time",
"tz_offset": -25200,
"profile": {
"avatar_hash": "8fbdd10b41c6",
"image_24": "https://a.slack-edge.com...png",
"image_32": "https://a.slack-edge.com...png",
"image_48": "https://a.slack-edge.com...png",
"image_72": "https://a.slack-edge.com...png",
"image_192": "https://a.slack-edge.com...png",
"image_512": "https://a.slack-edge.com...png",
"image_1024": "https://a.slack-edge.com...png",
"image_original": "https://a.slack-edge.com...png",
"first_name": "Glinda",
"last_name": "Southgood",
"title": "Glinda the Good",
"phone": "",
"skype": "",
"real_name": "Glinda Southgood",
"real_name_normalized": "Glinda Southgood",
"display_name": "Glinda the Fairly Good",
"display_name_normalized": "Glinda the Fairly Good",
"email": "glenda@south.oz.coven"
},
"is_admin": true,
"is_owner": false,
"is_primary_owner": false,
"is_restricted": false,
"is_ultra_restricted": false,
"is_bot": false,
"updated": 1480527098,
"has_2fa": false
}
],
"cache_ts": 1498777272,
"response_metadata": {
"next_cursor": "dXNlcjpVMEc5V0ZYTlo="
}
}
Response users typeデータ内容概説(主要なもの)
user.id
slack idで個人特定のための唯一のuniqe値
user.team_id
workspaceのid。 API上では、workspaceの旧来名称であるteamが出てくるので注意
user.name/ user.real_name
user.name == user.profile.display_name: メンションする際に出てくる名前(@….)
user.real_name == user.profile.real_name: 実際の登録名称
二つは一致していることもあれば、表示名を変更(initialとか名前のみとか)しているかたもいるので、差異が生じる場合がある。
user.deleted
ワークスペースに所属する/所属したことのあるユーザのうち、現在ワークスペースから外れているユーザ。外れている(所属していない)場合はTrue、所属している場合はFalse
これは、機能の一番最初に記載したように、Slackのワークスペースに過去も含め所属する/所属したことのあるユーザの一覧を取得するAPIであるため、現在の所属ステータスが表示される。
user.profile.image及びuser.profile.image_24/32/48/72/192/512
アイコン画像。imageがオリジナル画像。その他 image_24以降はそれぞれ解像度別データ
is_admin/is_owner など
is_ は各カテゴリ別の権限保有状況
留意事項とこんな使い方あるよ
私は現在userlist apiを現在利用している(アクティブな)ユーザ+botを抽出するAPIだと理解していましが、実際は過去に登録したことのあるユーザ+bot一覧が取得できます。
現在アクティブなユーザ等(bot含む)を取得する:
JSON取得後に、user.deleted==falseで抽出
退職者一覧を作る(業務委託先等社員以外にSlackを解放しておらず、社員は全てユーザ登録されている場合:
JSON取得後に、user.deleted==true及びuser.is_bot==falseで抽出