> ## 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 department list

> Call this API to get the basic information of the immediate sub-departments under a specified department; recursive retrieval of all sub-department levels is not supported.

Call this API to get the basic information of the next-tier departments. This API only returns the basic information of the immediate sub-departments of the current department. It does not return all sub-departments across every tier.

## Request

| **Basic information** |                                                                                                              |
| --------------------- | ------------------------------------------------------------------------------------------------------------ |
| HTTP URL              | [https://api.dingtalk.io/topapi/v2/department/listsub](https://api.dingtalk.io/topapi/v2/department/listsub) |
| HTTP Method           | POST                                                                                                         |
| Supported app types   | appType-Internal appappType-Third-party enterprise app                                                       |
| Permissions           | permission-qyapi\_get\_department\_list-Read permission for department information in Contacts               |

### Query parameters

| Name          | Type   | Required | Example  | Description                                                                                                                                                                                                                                                                                                      |
| ------------- | ------ | -------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Yes      | bE74xxxx | The app credential used to call this API.   - For an internal app, get it by calling the API for getting the [access\_token of an internal app](/open/development/obtain-orgapp-token). - For a third-party enterprise app, get it by calling the API for getting the access\_token of a third-party enterprise. |

### Request body

| Name     | Type   | Required | Example | Description                                                                                                     |
| -------- | ------ | -------- | ------- | --------------------------------------------------------------------------------------------------------------- |
| dept\_id | Number | No       | 1       | The parent department ID. Call the [Get the department list](#) API to get the value of the dept\_id parameter. |
| language | String | No       | zh\_CN  | The language of Contacts:   - **zh\_CN** (default): Chinese - **en\_US**: English                               |

### Request example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/v2/department/listsub" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=6846xxxx0cc781' \
-d 'dept_id=100' \
-d 'language=zh_CN'
```

Java

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/listsub");
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
req.setDeptId(1L);
req.setLanguage("zh_CN");
OapiV2DepartmentListsubResponse 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.OapiV2DepartmentListsubRequest("https://api.dingtalk.io/topapi/v2/department/listsub")

req.dept_id=100
req.language="zh_CN"
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 OapiV2DepartmentListsubRequest;
$req->setDeptId("100");
$req->setLanguage("zh_CN");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/v2/department/listsub");
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/listsub");
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
req.DeptId = 100L;
req.Language = "zh_CN";
OapiV2DepartmentListsubResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
```

## Response

### Response body

| Name                | Type                | Example               | Description                                                                                                                                                                     |
| ------------------- | ------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| request\_id         | String              | 5um7ykyaalsj          | The request ID.                                                                                                                                                                 |
| errcode             | Number              | 0                     | The return code.                                                                                                                                                                |
| errmsg              | String              | Invalid access\_token | The error message returned when the call failed.                                                                                                                                |
| result              | DeptBaseResponse\[] |                       | The department list.                                                                                                                                                            |
| dept\_id            | Number              | 100                   | The department ID.                                                                                                                                                              |
| name                | String              | HR                    | The department name.                                                                                                                                                            |
| parent\_id          | Number              | 50                    | The parent department ID.                                                                                                                                                       |
| create\_dept\_group | Boolean             | true                  | Whether to create an organization chat associated with this department at the same time:   - **true**: Create - **false**: Do not create                                        |
| auto\_add\_user     | Boolean             | false                 | After the Department Chat is created, whether new members who join the department are automatically added to the chat:   - **true**: Automatically added - **false**: Not added |

### Response example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0,
  "errmsg":"ok",
  "result": [
    {
      "auto_add_user": true,
      "create_dept_group": true,
      "dept_id": 37xxxx95,
      "name": "Marketing Department",
      "parent_id": 1
    },
    {
      "auto_add_user": true,
      "create_dept_group": true,
      "dept_id": 399xxxx96,
      "name": "Finance Department",
      "parent_id": 1
    }
  ],
  "request_id": "5um7ykyaalsj"
}
```

### Error codes

If the API call returns an error, find the solution in the [Global error codes](/open/development/server-api-error-codes-1) document based on the error message.

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