【发布时间】:2019-08-13 13:27:59
【问题描述】:
我正在 Zapier 中构建一个自定义集成,并遇到了一个问题,即我(对 Mavenlink)进行的 API 调用正在返回一个带有任意键的对象(在下面的示例中为 235896815)。但是,Zapier 在返回结果时只能使用数组(而不是对象)。我需要一种方法来获取返回对象中的数组而不知道键是什么。我有一个潜在的想法是始终返回索引处第一个对象的结果。这会是解决这个问题的最好方法吗?如果是这样,我将如何去做?也欢迎其他想法。
示例输出:
{
"235896915": {
"can_edit": true,
"subject_type": "story",
"account_id": 4150797,
"subject_id": 390078195,
"updated_at": "2019-03-21T14:26:16-07:00",
"value": [
1406325
],
"display_value": "Nicole Patel",
"setter_id": "10149395",
"custom_field_id": "181017",
"created_at": "2019-03-21T14:26:16-07:00",
"custom_field_name": "Active Assignee",
"type": "single",
"id": "235896915"
}
}
这是我正在打的电话:
const options = {
url: `https://api.mavenlink.com/api/v1/custom_field_values.json?subject_type=story&with_subject_id=${bundle.inputData.subject_id}`,
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${bundle.authData.access_token}`,
'Accept': 'application/json'
},
params: {
'subject_id': bundle.inputData.with_subject_id,
'id': bundle.inputData.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; //return object in an array
});
```
【问题讨论】:
-
只有on key吗?在这种情况下,
235896915。如果有多个,您要全部退回吗?
标签: javascript zapier