7
6

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.

curlでJSONをPOSTするとき値にシェル変数を使う方法について

Last updated at Posted at 2018-06-05

IFTTTのWebhookで困った

↓こういうの行けると思ったが…

curl -X POST -H "Content-Type: application/json" -d '{"value1":"$VAR1","value2":"$VAR2","value3":"$(cmd)"}' https://maker.ifttt.com/trigger/${EVENT_NAME}/with/key/${TOKEN}

Bad Requestが帰ってくる。
bash -xで調べると$VAR1や$(cmd)が文字列のまま実行されていた
シングルクォートのせい

とりあえず解決策

curl -X POST -H "Content-Type: application/json" -d @- https://maker.ifttt.com/trigger/${EVENT_NAME}/with/key/${TOKEN} << EOS
{"value1":"$VAR1","value2":"$VAR2","value3":"$(cmd)"}
EOS

もっといい方法がありましたらご教示ください

この記事はDeveloper I/Oさんを参考にしました。
https://dev.classmethod.jp/server-side/os/how-to-inject-variable-to-json-on-bash/

7
6
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
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?