我在构建私有Zapier集成方面有问题,因为Zapier只能将数组用作输出而不是对象。我需要调用的数组是嵌套在我的API结果中的2个级别,并且需要调用的密钥是任务所独有的变量(但是我可以使其成为输入数据的一部分)。
因此,要获得正确的数组,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];
});
这是我呼叫结果时的结果。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相同)。但是,即使对象每次都不同,也可以通过输入作为变量提供。
感谢任何愿意提供帮助的人!
您需要使用[]
符号 ref
更改此
"return results.custom_field_values.{bundle.inputData.id}"
到这个
"return results.custom_field_values[bundle.inputData.id]"
您是否尝试过括号表示法而不是点表示法?
类似的东西:
results.custom_field_values[{bundle.inputData.id}]
还确保bundle.inputData.id
是正确的值。