# Obtain parent department information

Call this interface to recursively obtain the parent department information of the specified department, including department name, ID, person in charge, status, etc.

## Precautions

- When this interface is called using the application identity (tenant_access_token), the interface only returns the parent department information within the visible range of the application contacts. For example, if there is a four-level department relationship of A > B > C > D, and the currently applied contacts permission only includes department B, then when querying the parent department information of department D, only the information of departments B and C will be returned, and A will not be returned. Department information. To understand the scope of authority, please refer to [Introduction to Authority Scope Resources](https://open.feishu.cn/document/ukTMukTMukTM/uETNz4SM1MjLxUzM/v3/guides/scope_authority).

- When calling this interface using user identity (user_access_token), only department information visible to the current user will be returned. The visible range of the user's organizational structure needs to be set by the enterprise administrator in [Admin](https://feishu.cn/admin/index) > **Security** > **Member Permissions** > **Visibility scope of organization** within, make adjustments.

- The parent departments that can be queried do not include the root department.

- When the returned list contains multiple department information, it will be displayed in order from sub-department to parent department.

## Request

Facts | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/contact/v3/departments/parent
HTTP Method | GET
Rate Limit | [Special Rate Limit](https://open.feishu.cn/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
Supported app types | Custom App、Store App
Required scopes<br>**To use this API, you must have at least 1 of the listed scopes.**<br>Enable any scope from the list | Get basic information in contacts(contact:contact.base:readonly)<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
Required field scopes | **Notice**：The response body of the API contains the following sensitive fields, and they will be returned only after corresponding scopes are added. If you do not need the fields, it is not recommended that you request the scopes.<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Obtain department's basic information(contact:department.base:readonly)<br>Obtain user ID(contact:user.employee_id:readonly)<br>View department HRBP info(contact:department.hrbp:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)

### Request header

Parameter | Type | Required | Description
---|---|---|---
Authorization | string | Yes | `tenant_access_token`<br>or<br>`user_access_token`<br>**Value format**: "Bearer `access_token`"<br>**Example value**: "Bearer u-7f1bcd13fc57d46bac21793a18e560"<br>[How to choose and get access token](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)

### Query parameters

Parameter | Type | Required | Description
---|---|---|---
user_id_type | string | No | User ID categories<br>**Example value**: open_id<br>**Optional values are**:<br>- open_id：Identifies a user to an app. The same user has different Open IDs in different apps. [How to get Open ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-openid)<br>- union_id：Identifies a user to a tenant that acts as a developer. A user has the same Union ID in apps developed by the same developer, and has different Union IDs in apps developed by different developers. A developer can use Union ID to link the same user's identities in multiple apps.[How to get Union ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-union-id)<br>- user_id：Identifies a user to a tenant. The same user has different User IDs in different tenants. In one single tenant, a user has the same User ID in all apps （including store apps）. User ID is usually used to communicate user data between different apps. [How to get User ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-user-id)<br>**Default value**: `open_id`<br>**When the value is `user_id`, the following field scopes are required**:<br>Obtain user ID(contact:user.employee_id:readonly)
department_id_type | string | No | The type of department ID in this call. For a detailed introduction to department ID, please refer to [Department ID Description](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/department/field-overview#23857fe0).<br>**Default**: open_department_id<br>**Example value**: open_department_id<br>**Optional values are**:<br>- department_id：Supports user-defined configured department IDs. The deleted department_id can be reused when customizing the configuration, so department_id is unique within the scope of the department that has not been deleted.<br>- open_department_id：Department ID automatically generated by the system. The ID prefix is fixed to `od-` and is globally unique within the tenant.
department_id | string | Yes | Department ID. The ID type needs to be consistent with the value of the query parameter department_id_type.<br>When you create a department, you can obtain the department ID information from the returned results. You can also call the [Search Department](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/department/search) interface to obtain all Required department ID.<br>**Example value**: od-4e6ac4d14bcd5071a37a39de902c7141
page_token | string | No | Page identifier. It is not filled in the first request, indicating traversal from the beginning; when there will be more groups, the new page_token will be returned at the same time, and the next traversal can use the page_token to get more groups<br>**Example value**: AQD9/Rn9eij9Pm39ED40/RD/cIFmu77WxpxPB/2oHfQLZ%2BG8JG6tK7%2BZnHiT7COhD2hMSICh/eBl7cpzU6JEC3J7COKNe4jrQ8ExwBCR
page_size | int | No | Paging size, used to limit the number of data entries returned in one request.<br>**Example value**: 10<br>**Default value**: `20`<br>**Data validation rules**:<br>- Maximum value: `50`

**Go Request Example**
```go
import (
	"context"

"github.com/larksuite/oapi-sdk-go/v3"
	"github.com/larksuite/oapi-sdk-go/v3/service/contact/v3"
)

func main() {
	client := lark.NewClient("appID", "appSecret")

req := larkcontact.NewParentDepartmentReqBuilder().
		DepartmentId(`od-4e6ac4d14bcd5071a37a39de902c7141`).
		PageSize(20).
		Build()

resp, err := client.Contact.Department.Parent(context.Background(), req)
}
```

**Java Request Example**
```java
import com.lark.oapi.Client;
import com.lark.oapi.core.request.RequestOptions;
import com.lark.oapi.service.contact.v3.model.ParentDepartmentReq;
import com.lark.oapi.service.contact.v3.model.ParentDepartmentResp;

public class Main {

public static void main(String arg[]) throws Exception {
        Client client = Client.newBuilder("appId", "appSecret").build();

ParentDepartmentReq req = ParentDepartmentReq.newBuilder()
                .departmentId("od-4e6ac4d14bcd5071a37a39de902c7141")
                .pageSize(20)
                .build();

ParentDepartmentResp resp = client.contact().department().parent(req, RequestOptions.newBuilder().build());
    }
}
```

## Response

### Response body

Parameter | Type | Description
---|---|---
code | int | Error codes, fail if not zero
msg | string | Error descriptions
data | \- | \-
has_more | boolean | Whether the response body has more parameters
page_token | string | Page identifier, when has_more is true, a new page_token will also be returned. Otherwise, page_token will not be returned
items | department\[\] | Department list.
name | string | Department name.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
i18n_name | department_i18n_name | International configuration of department names.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
zh_cn | string | Department's Chinese name.
ja_jp | string | Department's Japanese name.
en_us | string | Department's English name.
parent_department_id | string | The department ID of the parent department.<br>- The ID type is consistent with the department_id_type value of the query parameter.<br>- When the parent department is the root department, the parameter value is `0`.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
department_id | string | Custom department ID. This ID can be used later to delete, modify, and query department information.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
open_department_id | string | The open_department_id of the department is automatically generated by the system. This ID can be used later to delete, modify, and query department information.
leader_user_id | string | The user ID and ID type of the department head are consistent with the user_id_type value of the query parameter.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
chat_id | string | The group ID of the department group. You can later use [Get Group Information](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/get) to obtain the detailed information of the group.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
order | string | The sorting of departments is the order in which departments are displayed among departments at the same level. The smaller the value, the higher the sorting is.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
unit_ids | string\[\] | List of unit custom IDs bound to the department, currently only one is supported.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
member_count | int | The number of users (including department heads) in the current department and its subordinate departments.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
status | department_status | Department status.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's basic information(contact:department.base:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
is_deleted | boolean | Whether it is deleted.<br>**Possible values are:**<br>- true<br>- false
leaders | departmentLeader\[\] | Head of department.
leaderType | int | Person in charge type.<br>**Optional values are**:<br>- 1：Main person in charge<br>- 2：Deputy responsible person
leaderID | string | The user ID and ID type of the person in charge are consistent with the user_id_type value of the query parameter.<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)
group_chat_employee_types | int\[\] | Personnel type restrictions for department groups. Possible values for person type are as follows:<br>- 1: Regular employee<br>- 2: Intern<br>- 3: Outsourcing<br>- 4: Labor services<br>- 5: Consultant<br>If it is a custom person type, the corresponding number will be returned. You can call the [Query Personnel Type](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/contact-v3/employee_type_enum/list) interface to obtain the custom employee type information corresponding to the corresponding number (enum_value) .
department_hrbps | string\[\] | List of user IDs for department HRBP. The ID type is consistent with the value of the query parameter user_id_type.<br>**Required field scopes**:<br>View department HRBP info(contact:department.hrbp:readonly)
primary_member_count | int | The number of primary members of the current department and its subordinate departments (that is, the member's primary department is the current department).<br>**Required field scopes (Satisfy any)**:<br>Obtain department's organizational structure in contacts(contact:department.organize:readonly)<br>Access Contacts as an app(contact:contact:access_as_app)<br>Read contacts(contact:contact:readonly)<br>Read Contacts as an app(contact:contact:readonly_as_app)

### Response body example
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "has_more": true,
        "page_token": "AQD9/Rn9eij9Pm39ED40/RD/cIFmu77WxpxPB/2oHfQLZ%2BG8JG6tK7%2BZnHiT7COhD2hMSICh/eBl7cpzU6JEC3J7COKNe4jrQ8ExwBCR",
        "items": [
            {
                "name": "DemoName",
                "i18n_name": {
                    "zh_cn": "Demo name",
                    "ja_jp": "Name",
                    "en_us": "Demo Name"
                },
                "parent_department_id": "D067",
                "department_id": "D096",
                "open_department_id": "od-4e6ac4d14bcd5071a37a39de902c7141",
                "leader_user_id": "ou_7dab8a3d3cdcc9da365777c7ad535d62",
                "chat_id": "oc_5ad11d72b830411d72b836c20",
                "order": "100",
                "unit_ids": [
                    "custom_unit_id"
                ],
                "member_count": 100,
                "status": {
                    "is_deleted": false
                },
                "leaders": [
                    {
                        "leaderType": 1,
                        "leaderID": "ou_7dab8a3d3cdcc9da365777c7ad535d62"
                    }
                ],
                "group_chat_employee_types": [
                    1
                ],
                "department_hrbps": [
                    "ou_7dab8a3d3cdcc9da365777c7ad535d62"
                ],
                "primary_member_count": 100
            }
        ]
    }
}
```

### Error code

HTTP status code | Error code | Description | Troubleshooting suggestions
---|---|---|---
409 | 43001 | dept unit repeat error | Department unit ID conflicts.
409 | 43002 | dept unit is still using error | The unit ID of the department already exists.
409 | 43003 | multi dept unit error | Multiple department unit IDs exist.
400 | 43004 | illegal unit error | Invalid department unit ID
400 | 43005 | duplicate order error | The department order must be unique. Check the order and try again.
400 | 40001 | param error | Parameter error.
400 | 43007 | duplicated department custom id error | Duplicate department's custom ID in the company.
400 | 43008 | custom dept id invalid error | The custom department ID is invalid. It cannot start with "od-", cannot be "0", and cannot exceed 64 characters.
400 | 43009 | exceed update custom dept limit error | Your custom department ID quota has been used up.
400 | 43010 | big dept forbid recursion error | Unable to query a superdepartment.
400 | 43013 | dept too many children error | Too many sub-departments. The number of direct sub-departments of a department cannot exceed 1000.
400 | 43011 | delete has member dept error | The department to be deleted cannot contain any user. Check whether there is any user in the department.
400 | 43012 | delete has sub dept department error | The department to be deleted cannot contain any sub-department. Check whether there is any sub-department in the department.
400 | 40002 | process root dept error | Operation on the root department is not supported. Please check whether the root department ID `0` is passed in the request parameter department ID.
400 | 40003 | internal error | Internal error, please obtain the X-Request-Id of the request and provide feedback to [Technical Support](https://applink.feishu.cn/TLJpeNdW).
403 | 40004 | no dept authority error | The departments involved in the current operation need to be within the permission scope of the application contacts. For more information, please refer to [Permission Scope Resource Introduction](https://open.feishu.cn/document/ukTMukTMukTM/uETNz4SM1MjLxUzM/v3/guides/scope_authority).
400 | 40008 | dept Info is null error | Department information cannot be empty.
400 | 40010 | chat id is invalid error | Incorrect format of the department group ID
403 | 40014 | no parent dept authority error | There is no parent department permission. The parent department passed in needs to be within the address book permission scope of the application. For how to set the address book permission scope, see [Authority Scope Resource Introduction](https://open.feishu.cn/document/ukTMukTMukTM/uETNz4SM1MjLxUzM/v3/guides/scope_authority).
400 | 40011 | page size is invalid | Page size is invalid. The page_size parameter value passed in cannot exceed 50.
400 | 40012 | page token is invalid error | Page token is invalid. You need to check whether the page_token passed in is the page_token value returned by the last request.
401 | 42008 | tenant id is invalid error | Invalid tenant identity. When requesting, please ensure that the request header Authorization set and the resource to be operated belong to the same tenant.
400 | 44102 | miss department_id error | The request is missing department_id. The department_id parameter value must be passed in when requesting.

For more error code information, see [General error codes](https://open.feishu.cn/document/ukTMukTMukTM/ugjM14COyUjL4ITN).

