I am using search in Zapier. I have my own API which sends a single object when I search item by its item Id.
Below is response from API
{
"exists": true,
"data": {
"creationDate": "2019-05-23T10:11:18.514Z",
"Type": "Test",
"status": 1,
"Id": "456gf934a8aefdcab2eadfd22861",
"value": "Test"
}
}
when i search this by zap
Results must be an array, got: object, ({"exists":true,"data":{"creationDate":"2019-05-23T10:11:18.514Z)
Below is the 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
}
};
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"
}
},
}
};
The data you return from your perform must be of type "Array" (which starts with [
. You returned an object (a structure starting with {
).
The fix is simple enough - wrap your returned data in square brackets.
.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]
});