Skip to main content
Call this API to delete a specified user by user ID.

API call description

After you successfully delete a user from Contacts, the following data is also deleted:
  • The user is removed from the attendance group they belong to.
  • The user is removed from the Smart HR roster. You can view the user’s information under resigned employees in Smart HR.

Request

Basic information
HTTP URLhttps://oapi.dingtalk.io/topapi/v2/user/delete
HTTP MethodPOST
Supported app typesappType-Internal app
Permissions requiredpermission-qyapi_manage_addresslist-Contacts data management permission

Query parameter

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

Request body

NameTypeRequiredExampleDescription
useridStringYesuxxxx3The user ID of the employee.

Request example

curl -X POST "https://oapi.dingtalk.io/topapi/v2/user/delete" \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'access_token=0b8a6220-ef56-4427-83d5-5690431776e5' \
-d 'userid=zhangsan'
Java
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/v2/user/delete");
OapiV2UserDeleteRequest req = new OapiV2UserDeleteRequest();
req.setUserid("user123");
OapiV2UserDeleteResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
Python
import dingtalk.api

req=dingtalk.api.OapiV2UserDeleteRequest("https://oapi.dingtalk.io/topapi/v2/user/delete")

req.userid="zhangsan"
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 OapiV2UserDeleteRequest;
$req->setUserid("zhangsan");
$resp = $c->execute($req, $access_token, "https://oapi.dingtalk.io/topapi/v2/user/delete");
C#
IDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.io/topapi/v2/user/delete");
OapiV2UserDeleteRequest req = new OapiV2UserDeleteRequest();
req.Userid = "zhangsan";
OapiV2UserDeleteResponse rsp = client.Execute(req, access_token);
Console.WriteLine(rsp.Body);

Response

Response body

NameTypeExampleDescription
request_idString4f9md9obopn2The request ID.
errcodeNumber0The return code.
errmsgStringInvalid useridThe error message returned when the call failed.

Response body example

{
  "errcode": 0,
  "errmsg": "ok",
  "request_id": "4f9md9obopn2"
}

Error codes

If an error is returned when you call this API, refer to the global error codes document for solutions.
Error code (errcode)Error message (errmsg)Solution
33012Invalid userIdCheck whether the userId is correct.
400002Invalid parameterCheck whether the parameters are entered as required.
-1System busyTry again later.