Skip to main content
Call this API to remove roles from multiple employees in batch.

Request

Basic information
HTTP URLhttps://oapi.dingtalk.io/topapi/role/removerolesforemps
HTTP MethodPOST
Supported app typesappType-Internal app
Required permissionspermission-qyapi_manage_addresslist-Contacts data management permission

Query parameters

NameTypeRequiredExampleDescription
access_tokenStringYes6ed1bxxxThe App credential used to call this API. Obtain it through the API for getting the access_token of an internal app.

Request body

NameTypeRequiredExampleDescription
roleIdsStringYes1507113578The List of role roleIds. Call the Get role list API to obtain it. The maximum list length is 20. Separate multiple roleIds with commas (,).
userIdsStringYesuser100The user ID of the Employee. Call Query users by phone number to obtain the userId. The maximum list length is 100. Separate multiple userIds with commas (,).

Request example

curl -X POST "https://oapi.dingtalk.io/topapi/role/removerolesforemps" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=e56eb45d-4b5a-4284-bdcf-cbc5284e188a' \
-d 'roleIds=1507113578' \
-d 'userIds=user100'
Java
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/role/removerolesforemps");
OapiRoleRemoverolesforempsRequest req = new OapiRoleRemoverolesforempsRequest();
req.setRoleIds("1507113578");
req.setUserIds("user100,user101");
OapiRoleRemoverolesforempsResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
Python
import dingtalk.api

req=dingtalk.api.OapiRoleRemoverolesforempsRequest("https://oapi.dingtalk.io/topapi/role/removerolesforemps")

req.roleIds="1507113578"
req.userIds="user100"
try:
  resp= req.getResponse(access_token)
  print(resp)
except Exception,e:
  print(e)
PHP
include "TopSdk.php";
date_default_timezone_set('Asia/Shanghai');

$c = new DingTalkClient(DingTalkConstant::$CALL_TYPE_OAPI, DingTalkConstant::$METHOD_POST , DingTalkConstant::$FORMAT_JSON);
$req = new OapiRoleRemoverolesforempsRequest;
$req->setRoleIds("1,2");
$req->setUserIds("a,b");
$resp = $c->execute($req, $access_token, "https://oapi.dingtalk.io/topapi/role/removerolesforemps");
C#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/role/removerolesforemps");
OapiRoleRemoverolesforempsRequest req = new OapiRoleRemoverolesforempsRequest();
req.RoleIds = "1507113578";
req.UserIds = "user100";
OapiRoleRemoverolesforempsResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);

Response

Response body

NameTypeExampleDescription
errcodeNumber0The return code.
errmsgStringokThe description of the return code.
request_idString10c1rigbngrp5The request ID.

Response body example

{
  "errcode":0,
  "request_id":"10c1rigbngrp5"
}

Error codes

If an error is returned when you call this API, find the solution in the Global error codes document based on the error message.
Error code (errcode)Error message (errmsg)Solution
33011Invalid roleIdsCheck whether the roleIds are correct.
33012Invalid userIdCheck whether the userId is correct.
-1System busyTry again later.