# LINE 圖文選單 ###### tags: `line` `richmenu` 有兩種維護圖文選單<SUB>(rich menu)</SUB>的方式: 1. [LINE Official Account Manager](https://manager.line.biz/) 2. [Messaging API](https://developers.line.biz/en/docs/messaging-api/using-rich-menus/) 此筆記僅針對第二種方法。 [TOC] ## 創建 rich menu ``` POST https://api.line.me/v2/bot/richmenu HTTP/1.1 ``` | Header | | | --------------- | -------------------------------- | | `Authorization` | `Bearer ${CHANNEL_ACCESS_TOKEN}` | | `Content-Type` | `application/json` | Request body: ``` { "size": { "width": 2500, "height": 1686 }, "selected": true, "name": "Rich Menu 1", "chatBarText": "chatBarText", "areas": [ { "bounds": { "x": 0, "y": 0, "width": 833, "height": 843 }, "action": { "type": "postback", "label": "label 1", "data": "data", "displayText": "displayText" } }, { "bounds": { "x": 833, "y": 0, "width": 833, "height": 843 }, "action": { "type": "message", "label": "label 2", "text": "text" } }, { "bounds": { "x": 1666, "y": 0, "width": 833, "height": 843 }, "action": { "type": "uri", "label": "label 3", "uri": "https://zh.wikipedia.org/zh-tw/%E6%96%AF%E9%87%91%E7%BA%B3%E7%AE%B1" } } ] } ``` Response: ``` { "richMenuId": "richmenu-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } ``` ## 上傳 rich menu 圖檔 ``` POST https://api-data.line.me/v2/bot/richmenu/{richMenuId}/content HTTP/1.1 ``` | Header | | | --------------- | ---------------------------------------------- | | `Authorization` | `Bearer ${CHANNEL_ACCESS_TOKEN}` | | `Content-Type` | `image/jpeg`&#124;`image/jpg`&#124;`image/png` | ## 設為默認的 rich menu ``` POST https://api-data.line.me/v2/bot/user/all/richmenu/{richMenuId} HTTP/1.1 ``` | Header | | | --------------- | -------------------------------- | | `Authorization` | `Bearer ${CHANNEL_ACCESS_TOKEN}` | ## 將 rich menu 鏈接到單一用戶 ``` POST https://api.line.me/v2/bot/user/{userId}/richmenu/{richMenuId} HTTP/1.1 ``` | Header | | | --------------- | -------------------------------- | | `Authorization` | `Bearer ${CHANNEL_ACCESS_TOKEN}` | ## 將 rich menu 鏈接到多個用戶 ``` POST https://api.line.me/v2/bot/richmenu/bulk/link HTTP/1.1 ``` | Header | | | --------------- | -------------------------------- | | `Authorization` | `Bearer ${CHANNEL_ACCESS_TOKEN}` | | `Content-Type` | `application/json` | Request body: ``` { "richMenuId": "richmenu-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "userIds": [ "Uyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", "Uzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" ] } ``` Response: ``` {} ``` ## 獲取單一用戶鏈接的 rich menu ``` GET https://api.line.me/v2/bot/user/{userId}/richmenu HTTP/1.1 ``` | Header | | | --------------- | -------------------------------- | | `Authorization` | `Bearer ${CHANNEL_ACCESS_TOKEN}` | Response: ``` { "richMenuId": "richmenu-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } ``` ## 解除單一用戶鏈接的 rich menu ``` DELETE https://api.line.me/v2/bot/user/{userId}/richmenu HTTP/1.1 ``` | Header | | | --------------- | -------------------------------- | | `Authorization` | `Bearer ${CHANNEL_ACCESS_TOKEN}` | Response: ``` {} ``` ## 解除多個用戶鏈接的 rich menu ``` POST https://api.line.me/v2/bot/richmenu/bulk/unlink HTTP/1.1 ``` | Header | | | --------------- | -------------------------------- | | `Authorization` | `Bearer ${CHANNEL_ACCESS_TOKEN}` | | `Content-Type` | `application/json` | Request body: ``` { "userIds": [ "Uyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", "Uzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" ] } ``` Response: ``` {} ``` ## 解除默認的 rich menu ``` DELETE https://api.line.me/v2/bot/user/all/richmenu HTTP/1.1 ``` | Header | | | --------------- | -------------------------------- | | `Authorization` | `Bearer ${CHANNEL_ACCESS_TOKEN}` | Response: ``` {} ```