22
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

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

はじめに

ほぼ自分用の覚書

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(); //もげもげ
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
22
Help us understand the problem. What are the problem?