Request
| Basic information | |
|---|---|
| HTTP URL | https://api.dingtalk.io/topapi/role/addrolesforemps |
| HTTP Method | POST |
| Supported app types | appType-Internal app |
| Required permissions | permission-qyapi_manage_addresslist-Contacts data management permission |
Query parameters
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
| access_token | String | Yes | 6d1bxxxx | The app credential used to call this API. Obtain it through the API for getting the access_token of an internal app. |
Request body
| Name | Type | Required | Example | Description |
|---|---|---|---|---|
| roleIds | String | Yes | 1507113584 | The list of role IDs (roleId). Call the Get the list of roles API to obtain them. Separate multiple roleId values with commas (,). Up to 20 values are allowed. |
| userIds | String | Yes | user1 | The userId of an employee. Call Query users by phone number to obtain it. Separate multiple userId values with commas (,). Up to 20 values are allowed. |
Request example
curl -X POST "https://api.dingtalk.io/topapi/role/addrolesforemps" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=8f577dxxxx76f2a3a2' \
-d 'roleIds=1507113584' \
-d 'userIds=user1'
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/role/addrolesforemps");
OapiRoleAddrolesforempsRequest req = new OapiRoleAddrolesforempsRequest();
req.setRoleIds("1507113584,1507113589");
req.setUserIds("user1,user2");
OapiRoleAddrolesforempsResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
import dingtalk.api
req=dingtalk.api.OapiRoleAddrolesforempsRequest("https://api.dingtalk.io/topapi/role/addrolesforemps")
req.roleIds="1507113584"
req.userIds="user1"
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 OapiRoleAddrolesforempsRequest;
$req->setRoleIds("1507113584");
$req->setUserIds("user1");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/role/addrolesforemps");
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/role/addrolesforemps");
OapiRoleAddrolesforempsRequest req = new OapiRoleAddrolesforempsRequest();
req.RoleIds = "1507113584";
req.UserIds = "user1";
OapiRoleAddrolesforempsResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);
Response
Response body
| Name | Type | Example | Description |
|---|---|---|---|
| errcode | Number | 0 | The return code. |
| errmsg | String | ok | The description of the return code. |
| request_id | String | emhw6ma4xmeg | The request ID. |
Response body example
{
"errcode": 0,
"request_id": "emhw6ma4xmeg"
}
Error codes
If an error occurs when you call this API, refer to the Global error codes document to find a solution based on the error message.| Error code (errcode) | Error message (errmsg) | Solution |
|---|---|---|
| 33011 | Invalid roleIds | Check whether the roleIds are correct. |
| 33012 | Invalid userIds | Check whether the userId values are correct. |
| 12012 | The organization does not exist | Check whether the access_token is correct. |
| 1002 | System busy | Try again later. |