> ## Documentation Index
> Fetch the complete documentation index at: https://help.dingtalk.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Get the sub-department ID list

> Call this API to get the list of all direct sub-department IDs under a department, not subject to the authorization scope restriction.

# 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 URL              | [https://api.dingtalk.io/topapi/v2/department/listsubid](https://api.dingtalk.io/topapi/v2/department/listsubid) |
| HTTP Method           | POST                                                                                                             |
| Supported app types   | appType-Internal app, appType-Third-party enterprise app                                                         |
| Permissions           | permission-qyapi\_get\_department\_list-Read permission for Contacts department information                      |

### Query parameter

| Name          | Type   | Required | Example  | Description                                                                                                                                                                                                                                                                                                |
| ------------- | ------ | -------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Yes      | bE74xxxx | The 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](/open/development/obtain-orgapp-token). - For a third-party enterprise app, get it through the API for getting the access\_token of a third-party enterprise. |

### Request body

| Name     | Type   | Required | Example | Description                                                                                                                                                                                   |
| -------- | ------ | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| dept\_id | Number | Yes      | 1       | The parent department ID. Pass 1 for the root department. To get the dept\_id value, call the [Get the department list](/open/development/user-management-acquires-the-list-departments) API. |

### Request example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.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

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import dingtalk.api

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

req.dept_id=100
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
```

PHP

```php theme={"theme":{"light":"github-light","dark":"github-dark"}}
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://api.dingtalk.io/topapi/v2/department/listsubid");
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.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

| Name           | Type                  | Example               | Description                                     |
| -------------- | --------------------- | --------------------- | ----------------------------------------------- |
| request\_id    | String                | 48vhxdnwhve6          | The request ID.                                 |
| errcode        | Number                | 0                     | The return code.                                |
| errmsg         | String                | Invalid department ID | The error message returned when the call fails. |
| result         | DeptListSubIdResponse |                       | The returned result.                            |
| dept\_id\_list | Number\[]             | \[2,3,4,5]            | The sub-department list.                        |

### Response body example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "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](/open/development/server-api-error-codes-1) document to find a solution based on the error message.

| Error code (errcode) | Error message (errmsg)                    | Solution                                            |
| -------------------- | ----------------------------------------- | --------------------------------------------------- |
| 60003                | The corresponding department is not found | Verify that dept\_id is correct.                    |
| 400002               | Invalid parameter                         | Verify that the parameters are entered as required. |
| -1                   | System busy                               | Try again later.                                    |
