5
2

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 3 years have passed since last update.

【LINE Messaging API】Flex Message SimulatorでJSONを作成したときハマったこと

Last updated at Posted at 2021-06-21

LINE Messaging APIで Flex Message SimulatorでJSONを作ったときにハマったことをメモとして残します。

##症状
LINE FLEX MESSAGE SIMULATORで、FLEX MESSAGEを作成。

Image from Gyazo

さあ、JSONに変換
「View as JSON」をクリック
Image from Gyazo

JSONがでてきた。
これをコピーする。
Image from Gyazo

コードにペーストする。

replyMessage = {
  "type": "bubble",
  "body": {
    "type": "box",
    "layout": "vertical",
    "contents": [

          //中略

    ]
  }
}

しかし、これで実行すると、HTTPエラーになる。
HTTPError: Request failed with status code 400

なんで?
##解決策

LINE Developersのドキュメントをよく見ると、
https://developers.line.biz/ja/reference/messaging-api/#flex-message

冒頭にこれが必要でした。

"type": "flex",
  "altText": "this is a flex message",
  "contents": {

つまり、

replyMessage = {
  "type": "flex",
  "altText": "this is a flex message",
  "contents": {
    "type": "bubble",
    "body": {
      "type": "box",
      "layout": "vertical",
      "contents": [

          //中略

      ]
    }
  }
}

##反省点
公式ドキュメントをよく読もう!



5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?