Expected result
The department information is displayed as follows:Integration flow
- Obtain the app credential to get the client ID and Client Secret.
- Request the API permissions related to Contacts management.
-
Obtain the access credential to get the
access_tokenof the internal app. When you call an API, the access token is used to authenticate the caller. -
Call the Contacts APIs:
-
Call the Server API Create a department to create a department and obtain the
dept_id.- To create a sub-department under the root department, set
parent_idto 1. This example creates a sub-department under the root department. - To create a sub-department under another department, first call Get the department list to obtain the department ID, and then pass it as the value of
parent_id.
- To create a sub-department under the root department, set
-
Call the Server API Get department details with the
dept_idto retrieve department details. -
Call the Server API Update a department with the
dept_idto update department information. -
Call the Server API Delete a department with the
dept_idto delete a department.
-
Call the Server API Create a department to create a department and obtain the
Prerequisites
The Create and configure an app flow is completed.Step 1: Obtain the app credential
- Select the target app and go to the app details page. Click Basic information > Credentials and basic information.
- Get the client ID and Client Secret.
Step 2: Add API permissions
Click Development configuration > Manage permissions. In the permission search box, enterqyapi_manage_addresslist and qyapi_get_department_list, and then request the permissions.
Step 3: Obtain the access token
Important
- For details about the differences between the legacy and new Server APIs, see Legacy API vs. new API.
- To download the Server API SDK, see Download the Server-side SDK.
access_token of the internal app.
Step 4: Call the Contacts APIs
-
Call the Server API Create a department to create a department and obtain the
dept_id.-
To create a sub-department under the root department, set
parent_idto 1. This example creates a sub-department under the root department. -
To create a sub-department under another department, first call Get the department list to obtain the department ID, and then pass it as the value of
parent_id.
-
To create a sub-department under the root department, set
-
Call the Server API Get department details with the
dept_idto retrieve department details. -
Call the Server API Update a department with the
dept_idto update department information. -
Call the Server API Delete a department with the
dept_idto delete a department.Note- A department cannot be deleted if it contains users or if any of its sub-departments contain users.
- The department and all of its sub-departments will be deleted.
- After a department is deleted, its corresponding Department Chat is automatically dismissed.