gas
ifttt

IFTTTのWebhookをGASのPOSTで受け取るときのパラメータ覚書

More than 1 year has passed since last update.

はじめに

ほぼ自分用の覚書

JSONの場合

IFTTTの設定

  • URL: https://script.google.com/macros/s/XXXXXX/exec
  • Method: POST
  • Content Type: application/json
  • Body: {"value1": "moge", "value2": "もげもげ", "value3": "{{TextField}}}

GASの実装

sample.gs
function doPost(e) {
  var jsonString = e.postData.getDataAsString();
  var data = JSON.parse(jsonString);
  var value1 = data.value1; //moge
  var value2 = data.value2; //もげもげ
  var value3 = data.value3; //TextFieldの中身
}

x-www-form-urlencodedの場合

IFTTTの設定

  • URL: https://script.google.com/macros/s/XXXXXX/exec
  • Method: POST
  • Content Type:x-www-form-urlencoded
  • Body: value1=moge&values=hage&values=hoge

GASの実装

sample.gs
function doPost(e) {
  var moge = e.parameters["value1"][0];
  var hage = e.parameters["values"][0];
  var hoge = e.parameters["values"][1];
}

text/plainの場合

IFTTTの設定

  • URL: https://script.google.com/macros/s/XXXXXX/exec
  • Method: POST
  • Content Type:text/plain
  • Body: もげもげ

GASの実装

sample.gs
function doPost(e) {
  var body = e.postData.getDataAsString(); //もげもげ
}