Skip to main content

Get the sub-department ID list

API call description

  • This API is not restricted by the authorization scope.
  • This API only supports getting the ID list of the next level of departments.
For example, if you call this API to get the sub-department ID list of the root department, the result is [123,666]. Sub-departments under Department 1 and Department 2 cannot be retrieved.

Request

Basic information
HTTP URLhttps://oapi.dingtalk.io/topapi/v2/department/listsubid
HTTP MethodPOST
Supported app typesappType-Internal app, appType-Third-party enterprise app
Permissionspermission-qyapi_get_department_list-Read permission for Contacts department information

Query parameter

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

Request body

NameTypeRequiredExampleDescription
dept_idNumberYes1The parent department ID. Pass 1 for the root department. To get the dept_id value, call the Get the department list API.

Request example

curl -X POST "https://oapi.dingtalk.io/topapi/v2/department/listsubid" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=0dcxxxx108dcd028' \
-d 'dept_id=100'
Java
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/v2/department/listsubid");
OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
req.setDeptId(100L);
OapiV2DepartmentListsubidResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
Python
import dingtalk.api

req=dingtalk.api.OapiV2DepartmentListsubidRequest("https://oapi.dingtalk.io/topapi/v2/department/listsubid")

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 OapiV2DepartmentListsubidRequest;
$req->setDeptId("100");
$resp = $c->execute($req, $access_token, "https://oapi.dingtalk.io/topapi/v2/department/listsubid");
C#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/v2/department/listsubid");
OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
req.DeptId = 100L;
OapiV2DepartmentListsubidResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);

Response

Response body

NameTypeExampleDescription
request_idString48vhxdnwhve6The request ID.
errcodeNumber0The return code.
errmsgStringInvalid department IDThe error message returned when the call fails.
resultDeptListSubIdResponseThe returned result.
dept_id_listNumber[][2,3,4,5]The sub-department list.

Response body example

{
  "errcode": 0,
  "errmsg":"ok",
  "result": {
    "dept_id_list": [
      379xxxx95,
      411xxxx76,
      399xxxx96,
      400xxxx83,
      404xxxx47
    ]
  },
  "request_id": "169dfniaazqb4"
}

Error codes

If an error occurs when calling 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
60003The corresponding department is not foundVerify that dept_id is correct.
400002Invalid parameterVerify that the parameters are entered as required.
-1System busyTry again later.