Skip to main content

Get the user ID list of a department

API call description

  • This API is not restricted by the Contacts permission scope.
  • Getting the user IDs of all employees in your organization at once is not supported. To get the user IDs of all employees in your organization, use the following method:
    • Call the Get department list API and traverse level by level to get all department IDs within the authorized scope.
    • Call the API described in this document to get the user IDs of employees in each department.

Request

Basic information
HTTP URLhttps://oapi.dingtalk.io/topapi/user/listid
HTTP MethodPOST
Supported app typesappType-Internal app, appType-Third-party enterprise app
Required permissionpermission-qyapi_get_member-Read user information

Query parameter

NameTypeRequiredExampleDescription
access_tokenStringYesbE74xxxxThe app credential used to call this API. - For an internal app, obtain it through the API for getting the access_token of an internal app. - For a third-party enterprise app, obtain it through the API for getting the access_token of a third-party enterprise.

Request body

NameTypeRequiredExampleDescription
dept_idNumberYes100The deptId of the department. You can call Get department list to get the deptId. Note For the root department, set this parameter to 1.

Request example

curl -X POST "https://oapi.dingtalk.io/topapi/user/listid" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=03987655-598f-4f7a-8fc3-aaf257c47c27' \
-d 'dept_id=100'
Java
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/user/listid");
OapiUserListidRequest req = new OapiUserListidRequest();
req.setDeptId(100L);
OapiUserListidResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
Python
import dingtalk.api

req=dingtalk.api.OapiUserListidRequest("https://oapi.dingtalk.io/topapi/user/listid")

req.dept_id=100
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
PHP
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiUserListidRequest;
$req->setDeptId("100");
$resp = $c->execute($req, $access_token, "https://oapi.dingtalk.io/topapi/user/listid");
C#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/user/listid");
OapiUserListidRequest req = new OapiUserListidRequest();
req.DeptId = 100L;
OapiUserListidResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);

Response

Response body

NameTypeExampleDescription
request_idString4f9kasjdhopThe request ID.
errcodeNumber0The return code.
errmsgStringokThe description of the return code.
resultListUserByDeptResponseThe response result.
userid_listString[][“zxxxx”,“lixxxi”]The user ID list of the specified department.

Response example

{
  "errcode": 0,
  "errmsg":"ok",
  "result": {
    "userid_list": [
      "usxxx",
      "manager4xxx",
      "10203029011xxxx",
      "usexxx"
    ]
  },
  "request_id": "3naksldjh0dk"
}

Error codes

If an error occurs when you call this API, refer to the Global error codes document to find a solution based on the error message.
Error code (errcode)Error message (errmsg)Solution
60003Department not foundVerify that dept_id is correct.
400002Invalid parameterVerify that the parameters are valid.
-1System busyTry again later.