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

# Menetapkan cakupan pengelolaan anggota peran

> Panggil API DingTalk untuk menetapkan cakupan pengelolaan anggota peran di organisasi Anda. Dokumentasi lengkap parameter permintaan, contoh kode, dan struktur respons bagi developer.

Panggil API ini untuk menetapkan cakupan pengelolaan anggota peran.

## Permintaan

| **Informasi dasar**          |                                                                                                      |
| ---------------------------- | ---------------------------------------------------------------------------------------------------- |
| URL HTTP                     | [https://api.dingtalk.io/topapi/role/scope/update](https://api.dingtalk.io/topapi/role/scope/update) |
| Metode HTTP                  | POST                                                                                                 |
| Jenis aplikasi yang didukung | appType-Aplikasi internal                                                                            |
| Izin yang diperlukan         | permission-qyapi\_manage\_addresslist-Izin pengelolaan data Kontak                                   |

### Parameter kueri

| Nama          | Tipe   | Wajib | Contoh  | Deskripsi                                                                                                                                                            |
| ------------- | ------ | ----- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Ya    | Be3xxxx | Kredensial aplikasi untuk memanggil API ini. Dapatkan melalui API untuk memperoleh [access\_token dari aplikasi internal](/id/open/development/obtain-orgapp-token). |

### Isi permintaan

| Nama      | Tipe   | Wajib | Contoh | Deskripsi                                                                                                                                                           |
| --------- | ------ | ----- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| userid    | String | Ya    | EMP123 | ID pengguna karyawan di dalam organisasi.                                                                                                                           |
| role\_id  | Number | Ya    | 12345  | ID peran. Panggil API [Memperoleh daftar peran organisasi](/id/open/development/obtains-a-list-of-enterprise-roles) untuk memperoleh nilai parameter id.            |
| dept\_ids | String | Tidak | 1231   | Daftar ID departemen. Pisahkan beberapa ID departemen dengan koma. Maksimum 50 ID departemen didukung. Jika dibiarkan kosong, cakupan ditetapkan ke semua pengguna. |

### Contoh permintaan

```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);
```

## Respons

### Isi respons

| Nama        | Tipe   | Contoh       | Deskripsi                 |
| ----------- | ------ | ------------ | ------------------------- |
| errcode     | Number | 0            | Kode kembalian.           |
| errmsg      | String | ok           | Deskripsi kode kembalian. |
| request\_id | String | 4pe0h4hlsit9 | ID permintaan.            |

### Contoh isi respons

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

### Kode error

Jika error dikembalikan saat memanggil API ini, temukan solusinya di dokumen [Kode error global](/id/open/development/server-api-error-codes-1) berdasarkan pesan error.

| Kode error (errcode) | Deskripsi kode error (errmsg)       | Solusi                                     |
| -------------------- | ----------------------------------- | ------------------------------------------ |
| 40003                | Invalid userId                      | Pastikan userId sudah benar.               |
| 34018                | role\_id cannot be empty            | Berikan roleId.                            |
| 60301                | Invalid role\_id                    | Pastikan role\_id sudah benar.             |
| 60003                | Department does not exist           | Pastikan dept\_ids sudah benar.            |
| 46004                | Employee is not in the organization | Pastikan parameter sudah benar.            |
| 400002               | Invalid parameter                   | Pastikan parameter permintaan sudah benar. |
| -1                   | System busy                         | Coba lagi nanti.                           |
