Tec*_*ain 5 rest json zapier zapier-cli
我正在 Zapier 使用搜索。我有自己的 API,当我按项目 ID 搜索项目时,它会发送单个对象。
以下是 API 的响应
{
"exists": true,
"data": {
"creationDate": "2019-05-23T10:11:18.514Z",
"Type": "Test",
"status": 1,
"Id": "456gf934a8aefdcab2eadfd22861",
"value": "Test"
}
}
Run Code Online (Sandbox Code Playgroud)
当我用 zap 搜索这个时
结果必须是数组,got: object, ({"exists":true,"data":{"creationDate":"2019-05-23T10:11:18.514Z)
下面是代码
module.exports = {
key: 'item',
noun: 'itemexists',
display: {
label: 'Find an item',
description: 'check if item exist'
},
operation: {.
inputFields: [
{
key: 'itemid',
type: 'string',
label: 'itemid',
helpText: 'Eg. e3f1a92f72c901ffc942'
}
],
perform: (z, bundle) => {
const url = 'http://IP:8081/v1/itemexists/';
const options = {
params: {
itemId: bundle.inputData.itemid
}
};
return z.request(url, options)
.then(response => JSON.parse(response.content));
},
sample: {
"exists": true,
"data": {
"creationDate": "2019-05-23T10:11:18.514Z",
"Type": "Test",
"status": 1,
"Id": "456gf934a8aefdcab2eadfd22861",
"value": "Test"
}
},
}
};
Run Code Online (Sandbox Code Playgroud)
从执行中返回的数据必须是“Array”类型(以 开头[。您返回了一个对象(以 开头的结构{)。
修复方法非常简单 - 将返回的数据括在方括号中。
.then(response => [JSON.parse(response.content)]); // note the added `[]`
// or, if you don't care about the `exisits` key
.then(response => {
const data = JSON.parse(response.content)
return [data.data]
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2773 次 |
| 最近记录: |