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

# Set the management scope of a role member

> Call this API to set the management scope of a role member. Documents the request parameters and response structure.

Call this API to set the management scope of a role member.

## Request

| **Basic information** |                                                                                                      |
| --------------------- | ---------------------------------------------------------------------------------------------------- |
| HTTP URL              | [https://api.dingtalk.io/topapi/role/scope/update](https://api.dingtalk.io/topapi/role/scope/update) |
| HTTP Method           | POST                                                                                                 |
| Supported app type    | appType-Internal app                                                                                 |
| Required permissions  | permission-qyapi\_manage\_addresslist-Contacts data management permission                            |

### Query parameters

| Name          | Type   | Required | Example | Description                                                                                                                                                     |
| ------------- | ------ | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Yes      | Be3xxxx | The app credential for calling this API. Obtain it through the API for obtaining the [access\_token of an internal app](/open/development/obtain-orgapp-token). |

### Request body

| Name      | Type   | Required | Example | Description                                                                                                                                                           |
| --------- | ------ | -------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| userid    | String | Yes      | EMP123  | The user ID of the employee in the organization.                                                                                                                      |
| role\_id  | Number | Yes      | 12345   | The role ID. Call the [Obtain a list of organization roles](/open/development/obtains-a-list-of-enterprise-roles) API to obtain the value of the id parameter.        |
| dept\_ids | String | No       | 1231    | The list of department IDs. Separate multiple department IDs with commas. A maximum of 50 department IDs are supported. If left empty, the scope is set to all users. |

### Request example

```curl theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.dingtalk.io/topapi/role/scope/update" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=3100xxxx2280f5' \
-d 'dept_ids=1231' \
-d 'role_id=12345' \
-d 'userid=EMP123'
```

Java

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/role/scope/update");
OapiRoleScopeUpdateRequest req = new OapiRoleScopeUpdateRequest();
req.setUserid("EMP123");
req.setRoleId(12345L);
req.setDeptIds("1231,2423");
OapiRoleScopeUpdateResponse 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.OapiRoleScopeUpdateRequest("https://api.dingtalk.io/topapi/role/scope/update")

req.userid="EMP123"
req.role_id=12345
req.dept_ids="1231"
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 OapiRoleScopeUpdateRequest;
$req->setUserid("EMP123");
$req->setRoleId("12345");
$req->setDeptIds("1231,2423,53536");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/role/scope/update");
```

C#

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.dingtalk.io/topapi/role/scope/update");
OapiRoleScopeUpdateRequest req = new OapiRoleScopeUpdateRequest();
req.Userid = "EMP123";
req.RoleId = 12345L;
req.DeptIds = "1231";
OapiRoleScopeUpdateResponse 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 | 4pe0h4hlsit9 | The request ID.                     |

### Response body example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "errcode":"0",
  "errmsg":"ok",
  "request_id":"4pe0h4hlsit9"
}
```

### Error codes

If an error is returned when calling this API, find the solution in the [Global error codes](/open/development/server-api-error-codes-1) document based on the error message.

| Error code (errcode) | Error code description (errmsg)     | Solution                                        |
| -------------------- | ----------------------------------- | ----------------------------------------------- |
| 40003                | Invalid userId                      | Verify that the userId is correct.              |
| 34018                | role\_id cannot be empty            | Provide the roleId.                             |
| 60301                | Invalid role\_id                    | Verify that the role\_id is correct.            |
| 60003                | Department does not exist           | Verify that the dept\_ids are correct.          |
| 46004                | Employee is not in the organization | Verify that the parameters are correct.         |
| 400002               | Invalid parameter                   | Verify that the request parameters are correct. |
| -1                   | System busy                         | Try again later.                                |
