search
LoginSignup
94
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

Google Apps ScriptからHTTP POST

Google Driveのスプレットシートをハックしようと思って勉強してます。

ここのサンプルをもとに書いたらあっさりいけました。
Class UrlFetchApp - Google Apps Script — Google Developers -

サンプルリクエスト例

curl http://example.com -X POST -d 'message=google apps scriptより'

Google Apps Scriptで書くとこんな感じ

httppost.gs
/* 
* messageをpostする関数
*/
function sendHttpPost(message){
   var payload =
   {
     "message" : message
   };

   var options =
   {
     "method" : "post",
     "payload" : payload
   };

   UrlFetchApp.fetch("http://example.com", options);
}

function myFunction(){
  var message = 'google apps scriptより';
  sendHttpPost(message);
}

めちゃカンタンですね。

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
What you can do with signing up
94
Help us understand the problem. What are the problem?