LoginSignup
2
1

More than 5 years have passed since last update.

NodejsからGoogle Apps Script(GAS)のウェブ アプリケーションにPOSTする時にハマったこと

Posted at

概要

NodejsのrequestモジュールからGoogle Apps Script(GAS)のウェブアプリケーションにPOSTする際に、Moved Temporarilyとなり期待したPOSTとならない時の対処方法について紹介します

対処方法

requestのoptionにfollowAllRedirectsプロパティを追加することでリクエスト先でのリダイレクトを許可してあげることで期待した処理が得られる

const request = require('request');

const payload = {
  param1: 'param1',
  param2: 'param2'
};

const option = {
  uri: '<google apps script endpoint>',
  headers: {
    'Content-type': 'application/json'
  },
  json: true,
  followAllRedirects: true,
  form: payload
};

request.post(option, function(err, resp, body) {
  console.log(body);
});
2
1
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
2
1