【问题标题】:Why doesn't my Zapier Integration Dynamic Field work?为什么我的 Zapier 集成动态字段不起作用?
【发布时间】:2020-08-19 13:31:04
【问题描述】:

我构建了一个简单的 zapier 集成,它运行良好。但是,我正在添加动态字段。当我测试 zap 时,这一切似乎都运行良好。我的动态表单字段按预期显示。

问题是将这些动态表单的值发送到我的 API。我正在使用 zapier 控制台,当我配置 API 请求时,我正在使用以下内容:

body['custom_fields'] 应该发送我所有的动态字段甚至所有字段。但是当它到达我的 API 时,custom_fields 参数是空白的。

const options = {
  url: 'https://example_url/endpoint',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'Authorization': `Bearer ${bundle.authData.auth_token}`
  },
  body: {
    'email': bundle.inputData.email,
    'custom_fields': bundle.inputData

    /**
      I've tried the following with no luck:

     'custom_fields': bundle.inputData.fields
     'custom_fields': bundle.inputData.undefined
     'custom_fields': bundle.inputData
    */
  }
}

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    const results = response.json;

    // You can do any parsing you need for results here before returning them

    return results;
  });

【问题讨论】:

  • 您能否更新您的问题以包含您的inputFields 和/或动态字段生成代码? bundle.inputData 应该让一切都进入 zap

标签: zapier


【解决方案1】:

几天后好,这是最简单的答案。

显然一个对象不能通过参数发送。

所以而不是拥有

'custom_fields': bundle.inputData

我只是将整个对象添加到参数中,它会处理所有键和值

params: bundle.inputData

这是全身

const options = {
  url: 'https://apiendpoint.com',
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${bundle.authData.auth_token}`
  },
  params: bundle.inputData,

}

return z.request(options)
  .then((response) => {
    response.throwForStatus();
    const results = response.json;

    // You can do any parsing you need for results here before returning them

    return results;
  });

【讨论】:

    【解决方案2】:

    您可以使用扩展运算符...bundle.inputData,如文档中所述:

    https://platform.zapier.com/docs/input-designer#how-to-include-dynamic-fields-in-api-calls

    const options = {
      url: 'https://example_url/endpoint',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        'Authorization': `Bearer ${bundle.authData.auth_token}`
      },
      body: { ...bundle.inputData }
    }
    
    

    您甚至可以像这样命名您的请求数据:

      body: {
        request: { ...bundle.inputData }
      }
    

    注意:展开运算符在 Zapier 代码编辑器中引发语法错误,但它可以工作。

    【讨论】:

      猜你喜欢
      • 2018-02-28
      • 1970-01-01
      • 2017-04-23
      • 1970-01-01
      • 2022-07-07
      • 1970-01-01
      • 2019-11-10
      • 2016-04-22
      • 1970-01-01
      相关资源
      最近更新 更多