> ## 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 list of all parent departments of a specified department

> Call this API to get the list of all parent department IDs of a specified department. This API is not restricted by the Contacts permission scope.

Call this API to get the list of IDs of all parent departments of a specified department. This API is not restricted by the Contacts permission scope.

## Request

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

### Query parameters

| Name          | Type   | Required | Example  | Description                                                                                                                                                                                                                                                                                                      |
| ------------- | ------ | -------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Yes      | bE74xxxx | The 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](/open/development/obtain-orgapp-token). - For a third-party enterprise app, obtain 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      | 42xxxx36 | The ID of the department to query. Call the [Get department list](/open/development/user-management-acquires-the-list-departments) API to obtain the value of dept\_id. |

### Request example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/v2/department/listparentbydept" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=a456xxxx13da5' \
-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/listparentbydept");
OapiV2DepartmentListparentbydeptRequest req = new OapiV2DepartmentListparentbydeptRequest();
req.setDeptId(100L);
OapiV2DepartmentListparentbydeptResponse 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.OapiV2DepartmentListparentbydeptRequest("https://api.dingtalk.io/topapi/v2/department/listparentbydept")

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

C#

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

## Response

### Response body

| Name             | Type                           | Example               | Description                                                                                                                                                                                                                                                               |
| ---------------- | ------------------------------ | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| request\_id      | String                         | 10u9dj0853fwe         | The request ID.                                                                                                                                                                                                                                                           |
| errcode          | Number                         | 0                     | The return code.                                                                                                                                                                                                                                                          |
| errmsg           | String                         | Invalid department ID | The error message returned when the call failed.                                                                                                                                                                                                                          |
| result           | DeptListParentByDeptIdResponse |                       | The list of parent department IDs.                                                                                                                                                                                                                                        |
| parent\_id\_list | Number\[]                      | \[789, 456, 123, 1]   | The list of IDs of all parent departments of the department.  **Note**  In the returned list, the first element is the ID of the current department, and the last element is the ID of the top-level parent department. The department tier increases from left to right. |

### Response body example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0,
  "errmsg": "ok",
  "result": {
    "parent_id_list": [
      42xxxx36,
      1
    ]
  },
  "request_id": "ov7bc964j9pe"
}
```

### Error codes

If an error is returned when you call 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                                                  |
| -------------------- | ---------------------- | --------------------------------------------------------- |
| 43007                | Authorization required | Make sure the access\_token has the required permissions. |
| 60003                | Department not found   | Make sure dept\_id is correct.                            |
| 400002               | Invalid parameter      | Make sure the parameters are entered as required.         |
| -1                   | System busy            | Try again later.                                          |
