Zapier search expects array format but receives object response

I’m having trouble with my Zapier integration. When I perform a search through my API with a specific item’s ID, it returns a single object. However, Zapier shows an error indicating that it requires the results to be formatted as an array instead.

My API response looks like this:

{
    "found": true,
    "product": {
        "dateCreated": "2019-05-23T10:11:18.514Z",
        "category": "Sample",
        "active": 1,
        "productId": "789abc123def456ghi789jkl012",
        "name": "Sample Product"
    }
}

When I conduct the Zap test, I encounter the following error:

Results must be an array, got: object

Here’s my implementation:

module.exports = {
    key: 'product',
    noun: 'productlookup',
    display: {
        label: 'Search for product',
        description: 'verify if product exists'
    },

    operation: {
        inputFields: [
            {
                key: 'prodId',
                type: 'string',
                label: 'Product ID',
                helpText: 'Example: abc123def456ghi789'
            }
        ],

        perform: (z, bundle) => {
            const endpoint = 'http://SERVER:8081/api/productlookup/';
            const requestOptions = {
                params: {
                    productId: bundle.inputData.prodId
                }
            };

            return z.request(endpoint, requestOptions)
                .then(response => JSON.parse(response.content));
        },
        sample: {
            "found": true,
            "product": {
                "dateCreated": "2019-05-23T10:11:18.514Z",
                "category": "Sample",
                "active": 1,
                "productId": "789abc123def456ghi789jkl012",
                "name": "Sample Product"
            }
        }
    }
};

What can I do to modify this output so that Zapier will accept the response format?

zapier needs arrays for search operations, even for single items. just wrap your response in brackets: return [JSON.parse(response.content)] instead of returning the parsed object directly. that’ll fix your error.

Had this exact problem when I built my first Zapier integration last year. The error’s clear but the fix isn’t obvious if you’re coming from REST APIs that return objects for single lookups. Here’s what’s happening: Zapier treats all searches like they might return multiple results, so it always wants an array - even when you’re looking for just one item. You need to change your perform function to check if the product exists, then return it in array format. Don’t return the raw response. Instead, extract the product data and wrap it conditionally: const result = JSON.parse(response.content); return result.found && result.product ? [result.product] : []; This returns the product object wrapped in an array when it exists, or an empty array when nothing’s found. Also make sure your sample data uses the same array format or you’ll get weird behavior during testing.

The problem is that Zapier expects search operations to always return arrays, no matter how many results you get. You’re sending back the raw API response object, but you need to transform it first. Your API returns a response with a found flag and a nested product object. You need to pull out the actual product data and wrap it in an array. Here’s how to fix your perform function: return z.request(endpoint, requestOptions).then(response => { const data = JSON.parse(response.content); return data.found ? [data.product] : ; }); This handles both cases correctly. If found is true, you get an array with the product object. If it’s false, you get an empty array, which tells Zapier there weren’t any results.