6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

LINE botのリッチメニューを一括削除するシェルスクリプト

Last updated at Posted at 2019-06-07

LINE botのリッチメニューをAPI経由でいろいろ設定していたら、公式ページにこんなことが↓

1つのLINE公式アカウントに対して、Messaging APIを使って最大1000件のリッチメニューを作成できますが、この上限を超過すると、ステータスコード400 Bad Requestが返されます。その場合は、新しいリッチメニューを作成する前にリッチメニューを削除する必要があります。 リッチメニューを使う

一括で削除できたり、既存のリッチメニューを更新するAPIはみたところなかったので一括削除スクリプトをつくりました。(需要ないと思うけど一応公開)

# 変数の設定
ACCESS_TOKEN=...

# 一覧取得
existsMenus=$(
    curl -v -X GET https://api.line.me/v2/bot/richmenu/list \
        -H "Authorization: Bearer ${ACCESS_TOKEN}"
)
existsMenus=$(echo $existsMenus | jq ".richmenus")
existsMenusLen=$(echo $existsMenus | jq length)

# 1つずつ削除する
for i in $( seq 0 $(($existsMenusLen - 1)) ); do
    menu=$(echo $existsMenus | jq .[$i])
    menuId=$(echo $menu | jq ".richMenuId")
    menuId=$(echo ${menuId} | sed 's/"//g')

    curl -v -X DELETE https://api.line.me/v2/bot/richmenu/${menuId} \
        -H "Authorization: Bearer ${ACCESS_TOKEN}"
done

ちなみにJSONをあつかうのでjqコマンドが使える必要があります。(Macならbrew install jq)

おしりおわり

6
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?