Zapier Search: Receiving an Object Instead of an Array?

Using Zapier’s search, my API returns an object, not the expected array.

module.exports = {
  key: 'item_lookup',
  noun: 'Item',
  display: {
    label: 'Lookup an Item',
    description: 'Check if an item exists.'
  },
  operation: {
    inputFields: [{ key: 'itemID', type: 'string', label: 'Item ID', helpText: 'Eg. abc123xyz456' }],
    perform: (zap, data) => {
      const endpoint = 'http://example.com/api/lookup/';
      const config = {
        params: { id: data.inputData.itemID }
      };
      return zap.request(endpoint, config).then(res => JSON.parse(res.content));
    },
    sample: {
      check: true,
      details: {
        date: '2020-01-01T00:00:00Z',
        category: 'Example',
        state: 1,
        code: 'abc123xyz456',
        name: 'Sample Item'
      }
    }
  }
};

In my experience, such inconsistencies often stem from a mismatch between the API output and Zapier’s expectations. One effective approach is to manually adapt the output after the API call, checking if the returned value is an object and wrapping it in an array if needed. This ensures that subsequent Zap steps receive a uniform data structure. Validating the API design and confirming that the correct payload structure is transmitted can also help avoid such issues in the future.

hey hazel, i ran into a similar issue. mine was returning an obj so i simply wrapped it. try checking the type and then converting it to an array. works for me!