Zapier搜索功能报错:期望返回数组却得到对象的技术咨询
Hey there, the error you're hitting is a simple format mismatch: Zapier requires search operations to return an array of results, but your custom API sends back a single JSON object. Even if you only ever expect one matching item, Zapier needs that result wrapped in an array to process it correctly.
The Quick Fix
Modify your perform function to wrap the parsed API response in an array. Here's the adjusted code:
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 } }; // Wrap the parsed response object in an array 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"}}, } };
Optional Adjustment (If You Only Need the data Field)
If you don't need to pass the exists flag to Zapier and just want the item details, you can tweak the return line to pull out the data property instead:
return [JSON.parse(response.content).data];
Just make sure your sample object is updated to match this structure if you go this route—Zapier uses the sample to generate previews and map fields.
内容的提问来源于stack exchange,提问作者TechChain

