LoginSignup
0
0

z.requestのGETで配列パラメータを送る方法

Last updated at Posted at 2022-09-14

この記事は移行しました!最新の内容はこちらをご覧ください😀

zapier platform で Actions を設定している際、
GetのAPIに配列パラメータを渡したくてハマったのでメモ。

試行錯誤メモ

hogehoge?sort_by[]=id のように送りたい。

Input Designerではkeyに[]を指定できず。。

image.png

params では配列を送れない。。

const options = {
  url: 'hogehoge',
  method: 'GET',
  headers: {
  },
  params: {
    'page': bundle.meta.page + 1,
    'per_page': '50',
    'sort_by': ['id'],
    'sort_direction': ['desc']
  }
}

return z.request(options)

ベタ書きで検証してみたが hogehoge?sort_by=id になってしまう。
※実際は 'sort_by': bundle.inputData.sort_by としたい。ゴニョゴニョ書けばいけるのかも?

結論

body で渡した

body で渡す。
そしてGetメソッドに対し、body を有効にするには
allowGetBody: true
を指定する必要がありました。

const options = {
  url: 'hogehoge',
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json'
  },
  allowGetBody: true,
  body: {
    'per_page': bundle.inputData.per_page,
    'page': bundle.inputData.page,
    'sort_by': bundle.inputData.sort_by,
    'sort_direction': bundle.inputData.sort_direction
  }
}

return z.request(options)

設定メモ

配列の場合はAllows Multiplesにチェック
例)bundle.inputData.sort_by が配列となる

image.png

参考

0
0
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
0
0