3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GASのUrlFetchApp.fetch()関数で、「無効な引数」というエラーが出る場合

Last updated at Posted at 2019-10-08

概要

Google Apps Scriptの**UrlFetchApp.fetch()関数で、「無効な引数」**というエラーが出る場合の対処法です。
スクリーンショット 2019-10-08 18.30.09(2).png

対処法

リクエストのURIを送る際、特殊文字等が入ってることが原因の可能性があります。
URIエンコードをします。

以下はslack APIに投稿のリクエストを投げる場合の例です。

function postSlack(text){
  const token = hoge
  const channel = fuga

  response = UrlFetchApp.fetch(
  'https://slack.com/api/chat.postMessage?'
  + 'token=' + token
  + '&channel=' + channel
  + '&text=' + encodeURIComponent(text)); //原因となる部分をエンコードする

  Logger.log(JSON.parse(response.getContentText())); 
}

参考

Google apps script urlfetch encoding URL - Stack Overflow

3
1
1

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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?