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

# Delete a user

> Call this API to delete a specified user from the enterprise Contacts by userId, with request parameters and response fields.

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 URL              | [https://api.dingtalk.io/topapi/v2/user/delete](https://api.dingtalk.io/topapi/v2/user/delete) |
| HTTP Method           | POST                                                                                           |
| Supported app types   | appType-Internal app                                                                           |
| Permissions required  | permission-qyapi\_manage\_addresslist-Contacts data management permission                      |

### Query parameter

| Name          | Type   | Required | Example | Description                                                                                                                                                    |
| ------------- | ------ | -------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| access\_token | String | Yes      | Be3xxxx | 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                  |
| ------ | ------ | -------- | ------- | ---------------------------- |
| userid | String | Yes      | uxxxx3  | The user ID of the employee. |

### Request example

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -X POST "https://api.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

```java theme={"theme":{"light":"github-light","dark":"github-dark"}}
DingTalkClient client = new DefaultDingTalkClient("https://api.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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import dingtalk.api

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

req.userid="zhangsan"
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 OapiV2UserDeleteRequest;
$req->setUserid("zhangsan");
$resp = $c->execute($req, $access_token, "https://api.dingtalk.io/topapi/v2/user/delete");
```

C#

```csharp theme={"theme":{"light":"github-light","dark":"github-dark"}}
IDingTalkClient client = new DefaultDingTalkClient("https://api.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

| Name        | Type   | Example        | Description                                      |
| ----------- | ------ | -------------- | ------------------------------------------------ |
| request\_id | String | 4f9md9obopn2   | The request ID.                                  |
| errcode     | Number | 0              | The return code.                                 |
| errmsg      | String | Invalid userid | The error message returned when the call failed. |

### Response body example

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "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](/open/development/server-api-error-codes-1) document for solutions.

| Error code (errcode) | Error message (errmsg) | Solution                                              |
| -------------------- | ---------------------- | ----------------------------------------------------- |
| 33012                | Invalid userId         | Check whether the userId is correct.                  |
| 400002               | Invalid parameter      | Check whether the parameters are entered as required. |
| -1                   | System busy            | Try again later.                                      |
