Request
| Basic information | |
|---|---|
| HTTP URL | https://api.dingtalk.io/topapi/v2/department/listparentbyuser |
| HTTP Method | POST |
| Supported app types | appType-Internal appappType-Third-party enterprise app |
| Required permissions | 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. - 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 |
|---|---|---|---|---|
| userid | String | Yes | 100 | The user ID of the user to query. |
Request example
curl -X POST "https://api.dingtalk.io/topapi/v2/department/listparentbyuser" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=f3c2f4xxxxf65767' \
-d 'userid=100'
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/listparentbyuser");
OapiV2DepartmentListparentbyuserRequest req = new OapiV2DepartmentListparentbyuserRequest();
req.setUserid("100");
OapiV2DepartmentListparentbyuserResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
import dingtalk.api
req=dingtalk.api.OapiV2DepartmentListparentbyuserRequest("https://api.dingtalk.io/topapi/v2/department/listparentbyuser")
req.userid="100"
try:
resp= req.getResponse(access_token)
print(resp)
except Exception,e:
print(e)
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');
$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiV2DepartmentListparentbyuserRequest;
$req->setUserid("100");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/v2/department/listparentbyuser");
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/v2/department/listparentbyuser");
OapiV2DepartmentListparentbyuserRequest req = new OapiV2DepartmentListparentbyuserRequest();
req.Userid = "100";
OapiV2DepartmentListparentbyuserResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
Response
Response body
| Name | Type | Example | Description |
|---|---|---|---|
| errcode | Number | 0 | The return code. |
| request_id | String | nfe328zf67ec | The request ID. |
| errmsg | String | Invalid userid | The error message returned when the call failed. |
| result | DeptListParentByUserResponse | The returned result. | |
| parent_list | DeptParentResponse[] | The collection of parent department lists. | |
| parent_dept_id_list | Number[] | [456, 123, 1] | The parent department list. |
Response body example
{
"errcode": 0,
"errmsg":"ok",
"result": {
"parent_list": [
{
"parent_dept_id_list": [
37xxxx95,
1
]
}
]
},
"request_id": "nfe328zf67ec"
}
Error codes
If an error occurs when calling this API, find the solution in the Global error codes document based on the error message.| Error code (errcode) | Error message (errmsg) | Solution |
|---|---|---|
| 43007 | Authorization required | Confirm that the access_token has the required Permissions. |
| 33012 | Invalid userId | Confirm that the userId is correct. |
| 400002 | Invalid parameter | Confirm that the parameter is entered as required. |
| -1 | System busy | Try again later. |