Question

Array only returns first item on Search Zapier CLI

  • 22 August 2022
  • 4 replies
  • 36 views

Hello, I have a very simple question that I have not been able to find an answer to in the docs or here. I’m trying to create a custom Search Action that returns a list of objects. I’m trying to figure out how to return an array. 

 

I’m using Zapier CLI . Here is the sample code:

 

sample: [ {

  classes: [

     { name: "Test1",},

     {name: "Test2",},

   ],

}]

 

However Zapier CLI  throws an error: “sample is not of a type(s) object”

 

I would expect this to be the entire array, NOT throw an error or return just the first object. How do I correct this behavior so that my Zapier Action to return an array and correct the error?


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

4 replies

The error is telling you the exact problem:  it expects an object for the sample property, and you passed it an array. 

Thanks for the answer Tim.

But then what’s the best way to return on an action a list o items (array)?

 

For exemple a list of available cars on a dealership? It’s not on Search?
 

 

A lot of my early headaches with developing custom Zapier integrations was that I didn’t take the time (and honestly didn’t have it..) to really dig into the documentation to understand how the Zapier platform works under the hood.  

 

https://platform.zapier.com/cli_docs/docs#triggerssearchescreates

https://github.com/zapier/zapier-platform/blob/master/packages/schema/docs/build/schema.md

Userlevel 1
Badge +1

Hey Buka!

Christian here from Zapier's Platform Support team to confirm that Tim is absolutely correct.

In the schema documentation that Tim has kindly linked, we can see that the `sample` key is defined as requiring the `object` data type.

If you would like to return an array of items, you can assign the array to a property of the returned object - for example:

sample: {
classes: [
{name: "Test1"},
{name: "Test2"}
]
}

In this example, `sample` is an object containing the property `classes`, which contains an array of objects.

I hope this proves helpful!