使用输入数据变量作为获得Zapier结果的键(自定义集成)

问题描述 投票:0回答:2

我遇到了构建私有Zapier集成的问题,因为Zapier只能使用数组作为输出而不是对象。我需要调用的数组是嵌套在我的API结果中的两个级别,它需要调用的键是一个对所调用的任务唯一的变量(但我可以将它作为输入数据的一部分)。

因此,要获得正确的数组,javascript需要像"return results.custom_field_values[bundle.inputData.id]",但我找不到一种方法来获取结果中的输入数据变量,如。

这可能吗?我在支持文档中找不到解决方案。

这是我正在制作的电话:

const options = {
  url: `https://api.mavenlink.com/api/v1/custom_field_values.json?subject_type=story&with_subject_id=${bundle.inputData.subject_id}& custom_field_name=Active Assignee`,
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${bundle.authData.access_token}`,
    'Accept': 'application/json'
  },
  params: {
    'subject_id': bundle.inputData.with_subject_id,
    'display_value': 'Active Assignee'
  }
}

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

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

    return results.custom_field_values[bundle.inputData.id];
  });

当我只调用results.custom_field_values时,这是我的结果:

{
  "233451615": {
    "can_edit": true,
    "subject_type": "story",
    "account_id": 4150797,
    "subject_id": 385046515,
    "updated_at": "2019-03-18T13:54:28-07:00",
    "value": [
      638945
    ],
    "display_value": "Irma Davila",
    "setter_id": "10976265",
    "custom_field_id": "181017",
    "created_at": "2019-03-05T07:00:15-08:00",
    "custom_field_name": "Active Assignee",
    "type": "single",
    "id": "233451615"
  }
}

我要做的是只调用对象中的数组,在这种情况下是“233451615”(它与ID相同)。但是,即使对象每次都不同,也可以通过输入将其作为变量提供。

感谢愿意提供帮助的人!

javascript zapier
2个回答
0
投票

你需要使用[]符号Ref

改变这个

"return results.custom_field_values.{bundle.inputData.id}"

对此

"return results.custom_field_values[bundle.inputData.id]"

0
投票

您是否尝试过括号表示而不是点符号?

这样的事情:

results.custom_field_values[{bundle.inputData.id}]

还要确保bundle.inputData.id是正确的值。

© www.soinside.com 2019 - 2024. All rights reserved.