> ## 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.

# Add roles to multiple employees in bulk

> Call this API to add roles to multiple employees in bulk; roles in the default group such as owner, supervisor, main administrator, and sub-administrator cannot be added.

Call this API to add roles to multiple employees in bulk. Roles in the "Default" group, including Owner, Supervisor, Super Admin, and Sub Admin, cannot be added.

## Request

| **Basic information** |                                                                                                            |
| --------------------- | ---------------------------------------------------------------------------------------------------------- |
| HTTP URL              | [https://api.dingtalk.io/topapi/role/addrolesforemps](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](/open/development/obtain-orgapp-token). |

### Request body

| Name    | Type   | Required | Example    | Description                                                                                                                                                                                                              |
| ------- | ------ | -------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| roleIds | String | Yes      | 1507113584 | The list of role IDs (roleId). Call the [Get the list of roles](/open/development/obtains-a-list-of-enterprise-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](/open/development/query-users-by-phone-number) to obtain it.  Separate multiple userId values with commas (,). Up to 20 values are allowed.                |

### Request example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
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'
```

Java

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
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());
```

Python

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
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)
```

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 OapiRoleAddrolesforempsRequest;
$req->setRoleIds("1507113584");
$req->setUserIds("user1");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/role/addrolesforemps");
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
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

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode": 0,
  "request_id": "emhw6ma4xmeg"
}
```

### Error codes

If an error occurs 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                                     |
| -------------------- | ------------------------------- | -------------------------------------------- |
| 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.                             |
