# Remove users or bots from a group

Removes users or bots from a group chat.

## Prerequisites

Applications that call this interface need to enable [bot capability](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability).

## Usage restrictions

- Only group owners, group administrators, or robots that create groups and have the **Update the information of groups created by app (im:chat:operate_as_owner)** permission can remove other group members from the group.

- Users or robots can remove themselves from the group (i.e., quit the group on their own initiative) under any conditions.

- For each request, a maximum of 50 users or 5 robots can be removed.

- When operating an internal group, the operator must be in the same tenant as the group.

- When operating on the same group, if the current interface is called multiple times simultaneously, error code 232019 may occur. It is recommended to make serial calls, i.e., wait for the current call to complete before making the next call.

## Request

Facts | &nbsp;
---|---
HTTP URL | https://open.feishu.cn/open-apis/im/v1/chats/:chat_id/members
HTTP Method | DELETE
Rate Limit | [1000 per minute & 50 per second](https://open.feishu.cn/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
Supported app types | Custom App、Store App
Required scopes<br>**To use this API, you must have at least 1 of the listed scopes.**<br>Enable any scope from the list | Obtain and update group information(im:chat)<br>Add and remove group member(im:chat.members:write_only)
Required field scopes | **Notice**：The response body of the API contains the following sensitive fields, and they will be returned only after corresponding scopes are added. If you do not need the fields, it is not recommended that you request the scopes.<br>Obtain user ID(contact:user.employee_id:readonly)

### Request header

Parameter | Type | Required | Description
---|---|---|---
Authorization | string | Yes | `tenant_access_token`<br>or<br>`user_access_token`<br>**Value format**: "Bearer `access_token`"<br>**Example value**: "Bearer u-7f1bcd13fc57d46bac21793a18e560"<br>[How to choose and get access token](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)
Content-Type | string | Yes | **Fixed value**: "application/json; charset=utf-8"

### Path parameters

Parameter | Type | Description
---|---|---
chat_id | string | Group ID. How to get it:<br>- [Create a group](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/create), get the chat_id of the group from the returned result.<br>- Call the [Get the list of groups that the user or robot is in](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/list) interface to query the chat_id of the group that the user or robot is in.<br>- Call the [Search the list of groups visible to the user or robot](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/search) to search for the chat_id of the group that the user or robot is in and the group that is open to the user or robot.<br>**Note**: Only group IDs with group mode **group** and **topic** are supported. You can call the [get group information](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/get) interface and check whether the value of the `chat_mode` parameter is `group` or `topic` in the returned result.<br>**Example value**: "oc_a0553eda9014c201e6969b478895c230"

### Query parameters

Parameter | Type | Required | Description
---|---|---|---
member_id_type | string | No | User ID categories<br>**Example value**: open_id<br>**Optional values are**:<br>- open_id：Identifies a user to an app. The same user has different Open IDs in different apps. [How to get Open ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-openid)<br>- union_id：Identifies a user to a tenant that acts as a developer. A user has the same Union ID in apps developed by the same developer, and has different Union IDs in apps developed by different developers. A developer can use Union ID to link the same user's identities in multiple apps. [How to get Union ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-union-id)<br>- user_id：Identifies a user to a tenant. The same user has different User IDs in different tenants. In one single tenant, a user has the same User ID in all apps （including store apps）. User ID is usually used to communicate user data between different apps. [How to get User ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-user-id)<br>- app_id：The unique identifier of the Feishu open platform application. When an application is created, it is automatically generated by the system and cannot be modified by the user. [How to get App ID](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-app-id)<br>**Default value**: `open_id`<br>**When the value is `user_id`, the following field scopes are required**:<br>Obtain user ID(contact:user.employee_id:readonly)

### Request body

Parameter | Type | Required | Description
---|---|---|---
id_list | string\[\] | No | Member ID list. The ID type is consistent with the value of the query parameter member_id_type.<br>- It is recommended to use OpenID when removing users from the group. For how to obtain it, please refer to [How to get Open ID? ](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-openid).<br>- When removing bots from the group, you need to fill in the App ID of the application. Please refer to [How to get the App ID of the application?](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-app-id).<br>**Note**: <br>- ==id_list== cannot be empty.<br>- For each request, a maximum of 50 users or 5 bots can be removed.<br>**Example value**: ["4d7a3c6g"]

### Request body example
```json
{
    "id_list": [
        "4d7a3c6g"
    ]
}
```

## Response

### Response body

Parameter | Type | Description
---|---|---
code | int | Error codes, fail if not zero
msg | string | Error descriptions
data | \- | \-
invalid_id_list | string\[\] | Invalid member list

### Response body example
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "invalid_id_list": [
            "4d7a3c6g"
        ]
    }
}
```

### Error code

HTTP status code | Error code | Description | Troubleshooting suggestions
---|---|---|---
400 | 232001 | Your request contains an invalid request parameter. | Parameter error. Refer to the parameter description provided in the interface document to check whether the input parameters are correct.
400 | 232004 | Such an app does NOT exist. | The app_id as the operator doesn't exist. Please contact [technical support](https://applink.feishu.cn/TLJsX982).
400 | 232006 | Your request specifies a chat_id which is invalid. | Invalid chat_id, please check whether the chat_id is correct. How to obtain:<br>- [Create a group](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/create), and obtain the chat_id of the group from the returned result.<br>- Call the [Get the list of groups where the user or bot is](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/list) interface to query the chat_id of the group where the user or bot is.<br>- Call [Search the list of groups visible to users or bots](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat/search) to search for the chat_id of the group where the user or bot is and the group that is open to the user or bot.
400 | 232007 | Your request specifies a chat_id or user_id which is invalid. | Invalid chat_id or user_id
400 | 232009 | Your request specifies a chat which has already been dissolved. | The group has been deleted.
400 | 232010 | Operator and chat can NOT be in different tenants. | The operator and the group being operated should be under the same tenant.
400 | 232011 | Operator can NOT be out of the chat. | Operator can NOT be out of the chat.
400 | 232014 | The token used in the request does NOT have the permissions necessary to complete the request. | The operator does not have permission to perform this operation, please check whether it has the corresponding permission.
400 | 232019 | The request has been rate limited. | Rate-limiting is triggered. Pay attention to the request rate. For details, please see [Frequency Control Policy](https://open.feishu.cn/document/ukTMukTMukTM/uUzN04SN3QjL1cDN).<br>**Note**: When calling the [Add User or Bot to Group Chat](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-members/create) and [Remove User or Bot from Group Chat](https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-members/delete) APIs for the same group, multiple simultaneous calls may result in errors. It is recommended to call them sequentially, i.e., wait for the current call to complete before making the next call.
400 | 232025 | Bot ability is not activated. | The app does not have bot capabilities enabled. You need to log in to the [Developer Console](https://open.feishu.cn/app), add the **Bot** capability in **Features** > **Add Features** on the app details page, and publish the app to make the configuration effective. For specific operations, see [Bot Capabilities](https://open.feishu.cn/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability).
400 | 232027 | There are no valid members in the ID list specified in your request. | The member ID list is empty or no valid members exist.
400 | 232029 | There are no available candidates for chat owner. | No candidate group owner available
400 | 232033 | The operator or invited bots does NOT have the authority to manage external chats without the scope. | No permission to operate external groups.
400 | 232034 | The app is unavailable or inactivated by the tenant. | The app is unavailable or inactivated by the tenant.
400 | 232076 | Can't kick chat owner. | Chat owner can't be kicked.

For more error code information, see [General error codes](https://open.feishu.cn/document/ukTMukTMukTM/ugjM14COyUjL4ITN).

