コード
function doGet(e) {
console.log(e.parameter)
}
function doPost(e){
console.log(e.postData.contents)
}
叩く
GET
curl -X GET 'https://script.google.com/macros/s/hoge/exec?key1=value1&key2=value2'
POST
curl -X POST 'https://script.google.com/macros/s/hoge/exec' \
-H "Accept: application/json" -H "Content-type: application/json" \
-d '{"key1":"value1","key2":"value2"}'
ログ
両方とも
{"key1":"value1","key2":"value2"}
を得る。
ただ、GETの方はjsonで受け取るのに対し
POSTの方は文字列なので JSON.parse()
シテヤル必要あり
因みに
doPost(e)はparameterも受け取れるので
function doPost(e){
console.log(e.postData.contents)
console.log(e.parameter)
}
curl -X POST 'https://script.google.com/macros/s/hoge/exec?key3=value3' \
-H "Accept: application/json" -H "Content-type: application/json" \
-d '{"key1":"value1","key2":"value2"}'
とすれば両方受け取れる。
webhookとして使うときに重宝するのでぜひ。