服务端 API/群组/群菜单/添加群菜单
# 添加群菜单

该接口用于向群组中添加群菜单。

**注意事项**：注意事项：
- 该接口是向群内追加菜单，群内已存在的菜单不会被覆盖。
- 接口调用成功后，会返回当前群内所有群菜单。
- 应用需要开启[机器人能力](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)。
- 机器人必须在群里。
- 一个群内，一级菜单最多有3个，每个一级菜单最多有5个二级菜单。
- 暂不支持在一级菜单中追加二级菜单。
- 仅支持群模式为group的群组。

## 请求

基本 | &nbsp;
---|---
HTTP URL | https://open.larksuite.com/open-apis/im/v1/chats/:chat_id/menu_tree
HTTP Method | POST
接口频率限制 | [1000 次/分钟、50 次/秒](https://open.larksuite.com/document/ukTMukTMukTM/uUzN04SN3QjL1cDN)
支持的应用类型 | Custom App、Store App
权限要求<br>**调用该 API 所需的权限。开启其中任意一项权限即可调用**<br>开启任一权限即可 | 获取与更新群组信息(im:chat)<br>操作群菜单(im:chat.menu_tree:write_only)

### 请求头

名称 | 类型 | 必填 | 描述
---|---|---|---
Authorization | string | 是 | `tenant_access_token`<br>**值格式**："Bearer `access_token`"<br>**示例值**："Bearer t-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`的群ID<br>**示例值**："oc_a0553eda9014c201e6969b478895c230"

### 请求体

名称 | 类型 | 必填 | 描述
---|---|---|---
menu_tree | chat.menu_tree | 是 | 要向群内追加的菜单
chat_menu_top_levels | chat_menu_top_level\[\] | 是 | 一级菜单列表
chat_menu_item | chat_menu_item | 是 | 一级菜单信息
action_type | string | 是 | 菜单类型<br>**注意** <br>- 如果一级菜单有二级菜单时，则此一级菜单的值必须为NONE。<br>**示例值**："NONE"<br>**可选值有**：<br>- NONE：无类型<br>- REDIRECT_LINK：跳转链接类型
redirect_link | chat_menu_item_redirect_link | 否 | 跳转链接
common_url | string | 否 | 公用跳转链接，必须以http开头。<br>**示例值**："https://open.larksuite.com/"
ios_url | string | 否 | IOS端跳转链接，当该字段不设置时，IOS端会使用common_url。必须以http开头。<br>**示例值**："https://open.larksuite.com/"
android_url | string | 否 | Android端跳转链接，当该字段不设置时，Android端会使用common_url。必须以http开头。<br>**示例值**："https://open.larksuite.com/"
pc_url | string | 否 | PC端跳转链接，当该字段不设置时，PC端会使用common_url。必须以http开头。在PC端点击群菜单后，如果需要url对应的页面在Lark侧边栏展开，可以在url前加上https://applink.larksuite.com/client/web_url/open?mode=sidebar-semi&url=，比如https://applink.larksuite.com/client/web_url/open?mode=sidebar-semi&url=https://open.larksuite.com/<br>**示例值**："https://open.larksuite.com/"
web_url | string | 否 | Web端跳转链接，当该字段不设置时，Web端会使用common_url。必须以http开头。<br>**示例值**："https://open.larksuite.com/"
image_key | string | 否 | 图片的key值。通过 [上传图片](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/create) 接口上传message类型图片获取image_key<br>**注意** <br>- 如果一级菜单有二级菜单，则此一级菜单不能有图标。<br>**示例值**："img_v2_b0fbe905-7988-4282-b882-82edd010336j"
name | string | 是 | 菜单名称。<br>**注意**<br>- 一级、二级菜单名称字符数要在1到120范围内<br>**示例值**："群聊"
i18n_names | i18n_names | 否 | 菜单国际化名称。<br>**注意**<br>- 一级、二级菜单名称字符数要在1到120范围内
zh_cn | string | 否 | 中文名<br>**示例值**："评审报名"
en_us | string | 否 | 英文名<br>**示例值**："Sign up"
ja_jp | string | 否 | 日文名<br>**示例值**："サインアップ"
children | chat_menu_second_level\[\] | 否 | 二级菜单列表
chat_menu_item | chat_menu_item | 否 | 二级菜单信息
action_type | string | 否 | 菜单类型<br>**注意** <br>- 如果一级菜单有二级菜单时，则此一级菜单的值必须为NONE。<br>**示例值**："NONE"<br>**可选值有**：<br>- NONE：无类型<br>- REDIRECT_LINK：跳转链接类型
redirect_link | chat_menu_item_redirect_link | 否 | 跳转链接
common_url | string | 否 | 公用跳转链接，必须以http开头。<br>**示例值**："https://open.larksuite.com/"
ios_url | string | 否 | IOS端跳转链接，当该字段不设置时，IOS端会使用common_url。必须以http开头。<br>**示例值**："https://open.larksuite.com/"
android_url | string | 否 | Android端跳转链接，当该字段不设置时，Android端会使用common_url。必须以http开头。<br>**示例值**："https://open.larksuite.com/"
pc_url | string | 否 | PC端跳转链接，当该字段不设置时，PC端会使用common_url。必须以http开头。在PC端点击群菜单后，如果需要url对应的页面在Lark侧边栏展开，可以在url前加上https://applink.larksuite.com/client/web_url/open?mode=sidebar-semi&url=，比如https://applink.larksuite.com/client/web_url/open?mode=sidebar-semi&url=https://open.larksuite.com/<br>**示例值**："https://open.larksuite.com/"
web_url | string | 否 | Web端跳转链接，当该字段不设置时，Web端会使用common_url。必须以http开头。<br>**示例值**："https://open.larksuite.com/"
image_key | string | 否 | 图片的key值。通过 [上传图片](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/create) 接口上传message类型图片获取image_key<br>**注意** <br>- 如果一级菜单有二级菜单，则此一级菜单不能有图标。<br>**示例值**："img_v2_b0fbe905-7988-4282-b882-82edd010336j"
name | string | 否 | 菜单名称。<br>**注意**<br>- 一级、二级菜单名称字符数要在1到120范围内<br>**示例值**："群聊"
i18n_names | i18n_names | 否 | 菜单国际化名称。<br>**注意**<br>- 一级、二级菜单名称字符数要在1到120范围内
zh_cn | string | 否 | 中文名<br>**示例值**："评审报名"
en_us | string | 否 | 英文名<br>**示例值**："Sign up"
ja_jp | string | 否 | 日文名<br>**示例值**："サインアップ"

### 请求体示例
```json
{
    "menu_tree": {
        "chat_menu_top_levels": [
            {
                "chat_menu_item": {
                    "action_type": "NONE",
                    "redirect_link": {
                        "common_url": "https://open.larksuite.com/",
                        "ios_url": "https://open.larksuite.com/",
                        "android_url": "https://open.larksuite.com/",
                        "pc_url": "https://open.larksuite.com/",
                        "web_url": "https://open.larksuite.com/"
                    },
                    "image_key": "img_v2_b0fbe905-7988-4282-b882-82edd010336j",
                    "name": "群聊",
                    "i18n_names": {
                        "zh_cn": "评审报名",
                        "en_us": "Sign up",
                        "ja_jp": "サインアップ"
                    }
                },
                "children": [
                    {
                        "chat_menu_item": {
                            "action_type": "NONE",
                            "redirect_link": {
                                "common_url": "https://open.larksuite.com/",
                                "ios_url": "https://open.larksuite.com/",
                                "android_url": "https://open.larksuite.com/",
                                "pc_url": "https://open.larksuite.com/",
                                "web_url": "https://open.larksuite.com/"
                            },
                            "image_key": "img_v2_b0fbe905-7988-4282-b882-82edd010336j",
                            "name": "群聊",
                            "i18n_names": {
                                "zh_cn": "评审报名",
                                "en_us": "Sign up",
                                "ja_jp": "サインアップ"
                            }
                        }
                    }
                ]
            }
        ]
    }
}
```

## 响应

### 响应体

名称 | 类型 | 描述
---|---|---
code | int | 错误码，非 0 表示失败
msg | string | 错误描述
data | \- | \-
menu_tree | chat.menu_tree | 追加后群内现有菜单
chat_menu_top_levels | chat_menu_top_level\[\] | 一级菜单列表
chat_menu_top_level_id | string | 一级菜单ID
chat_menu_item | chat_menu_item | 一级菜单信息
action_type | string | 菜单类型<br>**注意** <br>- 如果一级菜单有二级菜单时，则此一级菜单的值必须为NONE。<br>**可选值有**：<br>- NONE：无类型<br>- REDIRECT_LINK：跳转链接类型
redirect_link | chat_menu_item_redirect_link | 跳转链接
common_url | string | 公用跳转链接，必须以http开头。
ios_url | string | IOS端跳转链接，当该字段不设置时，IOS端会使用common_url。必须以http开头。
android_url | string | Android端跳转链接，当该字段不设置时，Android端会使用common_url。必须以http开头。
pc_url | string | PC端跳转链接，当该字段不设置时，PC端会使用common_url。必须以http开头。在PC端点击群菜单后，如果需要url对应的页面在Lark侧边栏展开，可以在url前加上https://applink.larksuite.com/client/web_url/open?mode=sidebar-semi&url=，比如https://applink.larksuite.com/client/web_url/open?mode=sidebar-semi&url=https://open.larksuite.com/
web_url | string | Web端跳转链接，当该字段不设置时，Web端会使用common_url。必须以http开头。
image_key | string | 图片的key值。通过 [上传图片](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/create) 接口上传message类型图片获取image_key<br>**注意** <br>- 如果一级菜单有二级菜单，则此一级菜单不能有图标。
name | string | 菜单名称。<br>**注意**<br>- 一级、二级菜单名称字符数要在1到120范围内
i18n_names | i18n_names | 菜单国际化名称。<br>**注意**<br>- 一级、二级菜单名称字符数要在1到120范围内
zh_cn | string | 中文名
en_us | string | 英文名
ja_jp | string | 日文名
children | chat_menu_second_level\[\] | 二级菜单列表
chat_menu_second_level_id | string | 二级菜单ID
chat_menu_item | chat_menu_item | 二级菜单信息
action_type | string | 菜单类型<br>**注意** <br>- 如果一级菜单有二级菜单时，则此一级菜单的值必须为NONE。<br>**可选值有**：<br>- NONE：无类型<br>- REDIRECT_LINK：跳转链接类型
redirect_link | chat_menu_item_redirect_link | 跳转链接
common_url | string | 公用跳转链接，必须以http开头。
ios_url | string | IOS端跳转链接，当该字段不设置时，IOS端会使用common_url。必须以http开头。
android_url | string | Android端跳转链接，当该字段不设置时，Android端会使用common_url。必须以http开头。
pc_url | string | PC端跳转链接，当该字段不设置时，PC端会使用common_url。必须以http开头。在PC端点击群菜单后，如果需要url对应的页面在Lark侧边栏展开，可以在url前加上https://applink.larksuite.com/client/web_url/open?mode=sidebar-semi&url=，比如https://applink.larksuite.com/client/web_url/open?mode=sidebar-semi&url=https://open.larksuite.com/
web_url | string | Web端跳转链接，当该字段不设置时，Web端会使用common_url。必须以http开头。
image_key | string | 图片的key值。通过 [上传图片](https://open.larksuite.com/document/uAjLw4CM/ukTMukTMukTM/reference/im-v1/image/create) 接口上传message类型图片获取image_key<br>**注意** <br>- 如果一级菜单有二级菜单，则此一级菜单不能有图标。
name | string | 菜单名称。<br>**注意**<br>- 一级、二级菜单名称字符数要在1到120范围内
i18n_names | i18n_names | 菜单国际化名称。<br>**注意**<br>- 一级、二级菜单名称字符数要在1到120范围内
zh_cn | string | 中文名
en_us | string | 英文名
ja_jp | string | 日文名

### 响应体示例
```json
{
    "code": 0,
    "msg": "success",
    "data": {
        "menu_tree": {
            "chat_menu_top_levels": [
                {
                    "chat_menu_top_level_id": "7117116451961487361",
                    "chat_menu_item": {
                        "action_type": "NONE",
                        "redirect_link": {
                            "common_url": "https://open.larksuite.com/",
                            "ios_url": "https://open.larksuite.com/",
                            "android_url": "https://open.larksuite.com/",
                            "pc_url": "https://open.larksuite.com/",
                            "web_url": "https://open.larksuite.com/"
                        },
                        "name": "菜单",
                        "i18n_names": {
                            "zh_cn": "菜单",
                            "en_us": "Menu",
                            "ja_jp": "メニュー"
                        }
                    },
                    "children": [
                        {
                            "chat_menu_second_level_id": "7039638308221468675",
                            "chat_menu_item": {
                                "action_type": "REDIRECT_LINK",
                                "redirect_link": {
                                    "common_url": "https://open.larksuite.com/",
                                    "ios_url": "https://open.larksuite.com/",
                                    "android_url": "https://open.larksuite.com/",
                                    "pc_url": "https://open.larksuite.com/",
                                    "web_url": "https://open.larksuite.com/"
                                },
                                "image_key": "img_v2_b0fbe905-7988-4282-b882-82edd010336j",
                                "name": "报名",
                                "i18n_names": {
                                    "zh_cn": "报名",
                                    "en_us": "Sign up",
                                    "ja_jp": "サインアップ"
                                }
                            }
                        }
                    ]
                }
            ]
        }
    }
}
```

### 错误码

HTTP状态码 | 错误码 | 描述 | 排查建议
---|---|---|---
400 | 232001 | Your request contains an invalid request parameter. | 参数错误，参考本文档检查输入参数。
400 | 232008 | Your request specifies a chat whose type is NOT supported currently. | 不支持的群模式（chat_mode）或群类型（chat_type）。
400 | 232009 | Your request specifies a chat which has already been dissolved. | 群组已被解散。
400 | 232011 | 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. | 操作者没有权限进行该操作，请检查是否具有相应的权限。
400 | 232025 | Bot ability is not activated. | 应用需要开启[机器人能力](https://open.larksuite.com/document/uAjLw4CM/ugTN1YjL4UTN24CO1UjN/trouble-shooting/how-to-enable-bot-ability)。
400 | 232055 | The operator does not have chat tab, chat menu, chat widget manage permission | 没有会话标签页、会话菜单和小组件的管理权限，请检查群设置中“谁可以给管理会话标签页、会话菜单和小组件”是否开启了“仅群主和管理员”。
400 | 232034 | The app is unavailable or inactivated by the tenant. | 应用在本租户下未安装或未启用。
400 | 232056 | The operator is not the image's owner, no permission to complete the request. | 机器人需要使用自己上传的图片。
400 | 232070 | The number of chat_menu_top_level has reached the limit. | 群内一级菜单不能超过3个。
400 | 232071 | The number of chat_menu_second_level has reached the limit. | 群内二级菜单不能超过5个。
400 | 232073 | The group menu is being modified, please try again later. | 群内菜单正在修改中，请稍后重试。
400 | 232078 | The chat menu is illegal. | 群菜单内容非法。

