服务端 API/群组/群成员/将用户或机器人拉入群聊
# 将用户或机器人拉入群聊

将用户或机器人拉入群聊。

**注意事项**：注意事项：
 - 应用需要开启[机器人能力](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)
 - 如需拉用户进群，需要机器人对用户有[可用性](https://open.larksuite.com/document/home/introduction-to-scope-and-authorization/availability)
- 如需拉机器人进群，需要被拉的机器人开启[机器人能力](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)
 - 机器人或授权用户必须在群组中
- 外部租户不能被加入到内部群中
- 操作内部群时，操作者须与群组在同一租户下
 - 在开启 ==仅群主和群管理员可添加群成员== 的设置时，仅有群主/管理员 或 创建群组且具备 ==更新应用所创建群的群信息== 权限的机器人，可以拉用户或者机器人进群
 - 在未开启 ==仅群主和群管理员可添加群成员== 的设置时，所有群成员都可以拉用户或机器人进群

## 请求

基本 | &nbsp;
---|---
HTTP URL | https://open.larksuite.com/open-apis/im/v1/chats/:chat_id/members
HTTP Method | POST
接口频率限制 | [1000 次/分钟、50 次/秒](https://open.larksuite.com/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
支持的应用类型 | Custom App、Store App
权限要求<br>**调用该 API 所需的权限。开启其中任意一项权限即可调用**<br>开启任一权限即可 | 获取与更新群组信息(im:chat)<br>添加、移除群成员(im:chat.members:write_only)
字段权限要求 | **注意事项**：该接口返回体中存在下列敏感字段，仅当开启对应的权限后才会返回；如果无需获取这些字段，则不建议申请<br>获取用户 user ID(contact:user.employee_id:readonly)

### 请求头

名称 | 类型 | 必填 | 描述
---|---|---|---
Authorization | string | 是 | `tenant_access_token`<br>或<br>`user_access_token`<br>**值格式**："Bearer `access_token`"<br>**示例值**："Bearer u-7f1bcd13fc57d46bac21793a18e560"<br>[了解更多：如何选择与获取 access token](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-choose-which-type-of-token-to-use)
Content-Type | string | 是 | **固定值**："application/json; charset=utf-8"

### 路径参数

名称 | 类型 | 描述
---|---|---
chat_id | string | 群 ID，详情参见[群ID 说明](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/chat-id-description)<br>**注意**：仅支持群模式为`group`、`topic`的群组ID<br>**示例值**："oc_a0553eda9014c201e6969b478895c230"

### 查询参数

名称 | 类型 | 必填 | 描述
---|---|---|---
member_id_type | string | 否 | 用户 ID 类型<br>**示例值**：open_id<br>**可选值有**：<br>- open_id：标识一个用户在某个应用中的身份。同一个用户在不同应用中的 Open ID 不同。[了解更多：如何获取 Open ID？](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-openid)<br>- union_id：标识一个用户在某个应用开发商下的身份。同一用户在同一开发商下的应用中的 Union ID 是相同的，在不同开发商下的应用中的 Union ID 是不同的。通过 Union ID，应用开发商可以把同个用户在多个应用中的身份关联起来。[了解更多：如何获取 Union ID？](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-union-id)<br>- user_id：标识一个用户在某个租户内的身份。同一个用户在租户 A 和租户 B 内的 User ID 是不同的。在同一个租户内，一个用户的 User ID 在所有应用（包括商店应用）中都保持一致。User ID 主要用于在不同的应用间打通用户数据。[了解更多：如何获取 User ID？](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-user-id)<br>- app_id：Lark开放平台应用的唯一标识。在创建应用时，由系统自动生成，用户不能自行修改。[了解更多：如何获取应用的 App ID？](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-app-id)<br>**默认值**：`open_id`<br>**当值为 `user_id`，字段权限要求**：<br>获取用户 user ID(contact:user.employee_id:readonly)
succeed_type | int | 否 | 出现不可用ID后的处理方式 0/1/2<br>**默认值**：`0`<br>**示例值**：0<br>**可选值有**：<br>- 0：兼容之前的策略，不存在/不可见的 ID 会拉群失败，并返回错误响应。存在已离职 ID 时，会将其他可用 ID 拉入群聊，返回拉群成功的响应。<br>- 1：将参数中可用的 ID 全部拉入群聊，返回拉群成功的响应，并展示剩余不可用的 ID 及原因。<br>- 2：参数中只要存在任一不可用的 ID ，就会拉群失败，返回错误响应，并展示出不可用的 ID。

### 请求体

名称 | 类型 | 必填 | 描述
---|---|---|---
id_list | string\[\] | 否 | 成员ID列表。邀请用户进群时推荐使用 OpenID，获取方式可参考文档[如何获取 Open ID？](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-openid)；邀请机器人进群时需填写应用的App ID，请参考[如何获取应用的 App ID？](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-obtain-app-id)<br>**注意**：<br>- 成员列表不可为空<br>- 列表中填写的成员ID类型应与 ==member_id_type== 参数中选择的类型相对应<br>- 每次请求最多拉50个用户且不超过群人数上限。对于已认证企业的Lark的群人数默认上限：普通群5000人，会议群3000人，话题群5000人。若租户管理员配置了群人数上限，则群人数上限为该人数上限<br>- 最多同时邀请5个机器人，且邀请后群组中机器人数量不能超过 15 个<br>**示例值**：["4d7a3c6g"]

### 请求体示例
```json
{
    "id_list": [
        "4d7a3c6g"
    ]
}
```

## 响应

### 响应体

名称 | 类型 | 描述
---|---|---
code | int | 错误码，非 0 表示失败
msg | string | 错误描述
data | \- | \-
invalid_id_list | string\[\] | 无效成员列表<br>**注意**：<br>- 当`success_type=0`时，`invalid_id_list`只包含已离职的用户ID<br>- 当`success_type=1`时，`invalid_id_list`中包含已离职的、不可见的、应用未激活的ID
not_existed_id_list | string\[\] | ID不存在的成员列表
pending_approval_id_list | string\[\] | 等待群主或管理员审批的成员ID列表

### 响应体示例
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "invalid_id_list": [
            "4d7a3c6g"
        ],
        "not_existed_id_list": [
            "4d7a3c6g"
        ],
        "pending_approval_id_list": [
            "4d7a3c6g"
        ]
    }
}
```

### 错误码

HTTP状态码 | 错误码 | 描述 | 排查建议
---|---|---|---
400 | 232001 | Your request contains an invalid request parameter. | 参数错误，参考本文档检查输入参数。
400 | 232004 | Such an app does NOT exist. | 作为操作者的 app_id 不存在，请联系[技术支持](https://applink.larksuite.com/TLJsX982)。
400 | 232006 | Your request specifies a chat_id which is invalid. | 无效的 chat_id，请检查chat_id是否正确。
400 | 232009 | Your request specifies a chat which has already been dissolved. | 群组已被解散。
400 | 232010 | Operator and chat can NOT be in different tenants. | 操作者和被操作的群组应该在同一租户下。
400 | 232011 | Operator can NOT be out of the chat. | 操作者需要在群组中。
400 | 232013 | You have reached the limit of maximum number of members a chat can have. | 加入群组时，群成员数量已达到上限。对于已认证企业的Lark的群人数默认上限：普通群5000人，会议群3000人，话题群5000人。
400 | 232017 | No Permission: If the operator is NOT owner or creator with the scope, the operator can NOT complete the request. | 操作者在群中不具备群主、群创建者等身份，无法完成本操作。
400 | 232019 | The request has been rate limited. | 触发群限流，请控制请求的速度，详情参见[频控策略](https://open.larksuite.com/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)。
400 | 232024 | Users do not have the visibility of the app, or the operator does not have collaboration permissions with the target users. | 机器人对用户没有可见性，或操作者与用户间没有协作权限。前者可在[开发者后台](https://open.larksuite.com/app)-应用发布-版本管理与发布 编辑应用对用户的可见性并发布；后者请检查是否与目标用户有协作权限，如屏蔽、未添加未联系人等。
400 | 232025 | Bot ability is not activated. | 应用需要开启[机器人能力](https://open.larksuite.com/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. | 成员ID列表为空或不存在有效的成员。
400 | 232028 | External members can Not be added to an internal group chat. | 外租户成员不能被加入内部群。
400 | 232033 | The operator or invited bots does NOT have the authority to manage external chats without the scope. | 没有权限操作外部群，且暂不支持申请该权限。
400 | 232034 | The app is unavailable or inactivated by the tenant. | 应用在本租户下未安装或未启用。
400 | 232043 | Your request contains unavailable ids. | 请检查传入的 ID 列表。
400 | 232044 | You have reached maximum number of chat members set by admin. | 群成员人数已达到租户管理员配置的上限，如需提高上限请向租户管理员申请。
400 | 232090 | Unsupported chat type. | 不支持的群类型，无法完成本操作。
400 | 99992351 | Your request contains not existed id. | 部分 open_id 不存在，请检查后重试。
400 | 99992360 | Your request contains not existed id. | 部分 user_id 不存在，请检查后重试。
400 | 99992364 | Your request contains not existed id. | 部分 union_id 不存在，请检查后重试。

