跳至主要内容

取得部門成員列表

分頁取得指定部門下的直属成員列表。

介面資訊​

項目說明
介面名稱取得部門成員列表
權限標識contact.department.read(讀取組織架構)
請求方式POST / GET
請求地址https://{gateway_host}/open/v1/contact/user/list
資料格式application/json(POST 時)或 URL Query
鑑權方式應用級 access_token(需具備 contact.department.read 權限)

前置條件​

  1. 應用已在管理後臺「內部應用」中發布並啟用。
  2. 已取得有效的應用級 access_token。
  3. 目標部門必須在應用的可見範圍內。

請求參數​

參數名類型必填說明
access_tokenstring是應用級令牌(未在 Authorization 標頭中攜帶時必填)
dept_idstring是部門 ID(正整數字串)。必填,不能省略;單根部門授權時可傳 "1" 作為根映射。相容別名 deptId、departmentId、department_id
cursorstring否從 0 開始的數字偏移量,預設 0;相容別名 next_cursor、nextCursor
sizeinteger否每頁成員數,範圍 1–100,預設 100
languagestring否語言/國際化保留參數,目前不影響返回內容

請求範例​

POST https://{gateway_host}/open/v1/contact/user/list
Authorization: Bearer <access_token>
Content-Type: application/json

{ "dept_id": "20", "cursor": "0", "size": 50 }
GET https://{gateway_host}/open/v1/contact/user/list?dept_id=20&cursor=0&size=50
Authorization: Bearer <access_token>

回應參數​

{
"code": 200,
"msg": "",
"data": {
"users": [{
"userId": "42", "name": "張三", "avatar": "https://cdn.example.com/avatar/42.png",
"mobile": "13800000000", "email": "zhangsan@example.com", "jobNumber": "A-001", "title": "工程師", "deptIdList": ["10", "20"]
}],
"hasMore": true,
"nextCursor": "1"
}
}
欄位類型說明
codeinteger業務狀態碼;200 表示成功
msgstring訊息;成功時為空
data.usersobject[]成員列表;沒有成員時為 [],欄位與取得成員詳情介面一致
data.users[].userIdstring成員 ID
data.users[].namestring成員暱稱/姓名
data.users[].avatarstring頭像 URL;未設定時省略
data.users[].mobilestring手機號碼;未設定時省略
data.users[].emailstring電子郵件;未設定時省略
data.users[].jobNumberstring工號;未設定時省略
data.users[].titlestring職稱;未設定時省略
data.users[].deptIdListstring[]成員所屬部門 ID 列表(僅包含可見部門)
data.hasMoreboolean是否還有更多成員
data.nextCursorstring下一頁游標;僅在 hasMore=true 時返回,下一次請求作為 cursor 傳入

返回規則與注意事項​

  1. 只返回直属成員,不遞迴:本介面只返回直接隸屬於指定部門的成員,不會展開子部門成員。需要子部門成員時,先用部門列表介面取得子部門 ID,再逐一呼叫本介面。
  2. 欄位完整,不需逐一補查:返回的成員物件包含全部公開成員欄位,不需要再逐一呼叫詳情介面。
  3. 按可見範圍過濾:只返回應用可見範圍內的正常成員;應用無權查看的成員即使直接隸屬該部門,也會被省略。
  4. 分頁終止條件:嚴格使用 hasMore 和 nextCursor 判斷是否完成,不要用當前頁數量小於 size 判斷。

錯誤碼​

HTTP 狀態碼msg 錯誤碼說明
401INVALID_TOKEN令牌缺失、過期、撤銷,或應用不可用
403SCOPE_DENIED令牌缺少 contact.department.read 權限
403IP_DENIED來源 IP 不在應用安全設定的 IP 白名單中
200 / code=500INVALID_REQUESTdept_id 缺失、為空、不是正整數,cursor 格式錯誤或 size 超出 1–100
200 / code=500DEPARTMENT_NOT_FOUND部門不存在、已刪除或超出應用可見範圍
200 / code=500PERMISSION_DENIED應用狀態無效
200 / code=500SERVER_ERROR服務端異常,請稍後重試

多語言呼叫範例​

Shell​

curl -sS -X POST "https://{gateway_host}/open/v1/contact/user/list" -H "Authorization: Bearer access-token-xxx" -H "Content-Type: application/json" -d '{"dept_id":"20","cursor":"0","size":50}'

PHP​

<?php
// 生產環境應檢查 HTTP 狀態和回應體,再映射業務錯誤。
$handle = curl_init('https://{gateway_host}/open/v1/contact/user/list'); curl_setopt_array($handle, [CURLOPT_POST => true, CURLOPT_HTTPHEADER => ['Authorization: Bearer access-token-xxx', 'Content-Type: application/json'], CURLOPT_POSTFIELDS => '{"dept_id":"20","cursor":"0","size":50}', CURLOPT_RETURNTRANSFER => true]); echo curl_exec($handle); curl_close($handle);

Golang​

package main
import ("bytes"; "net/http")
func main() { request, _ := http.NewRequest(http.MethodPost, "https://{gateway_host}/open/v1/contact/user/list", bytes.NewBufferString(`{"dept_id":"20","cursor":"0","size":50}`)); request.Header.Set("Authorization", "Bearer access-token-xxx"); response, _ := http.DefaultClient.Do(request); defer response.Body.Close() }

C++​

#include <curl/curl.h>
int main() { CURL* handle = curl_easy_init(); struct curl_slist* headers = curl_slist_append(nullptr, "Authorization: Bearer access-token-xxx"); curl_easy_setopt(handle, CURLOPT_URL, "https://{gateway_host}/open/v1/contact/user/list"); curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(handle, CURLOPT_POSTFIELDS, R"({"dept_id":"20","cursor":"0","size":50})"); const CURLcode result = curl_easy_perform(handle); curl_slist_free_all(headers); curl_easy_cleanup(handle); return result == CURLE_OK ? 0 : 1; }