Question

Does bundle.inputData.brands count as an array?

  • 13 April 2022
  • 2 replies
  • 235 views

I made an integration to retrieve products from my API, elaborate them and pass them to whatever action a user wants. For testing i made a Zap that loads all the product’s information in a row of a google spreadsheet.

From the CLI in local the testing always works. The input fields with the filters are defined as follow :

inputFields: [

{

key: 'respect_all_filters',

label: 'Respect all filters',

helpText: 'Would you like to import every product that respect ALL filters? Select false if for example you want to import all product with a certain brand AND all product with a certain category but not the same brand.',

type: 'boolean',

default: 'false',

required: true

},

{

key: 'brand',

label: 'Brand',

helpText: 'Choose the brand of the products you want to import. Leave it empty if you do not want to filter.',

required: false,

list: true

},

{

key: 'category',

label: 'Category',

helpText: 'Choose the category of the products you want to import. Leave it empty if you do not want to filter.',

required: false,

list: true

},

{

key: 'sub_category',

label: 'Sub Category',

helpText: 'Choose the sub category of the products you want to import. Leave it empty if you do not want to filter.',

required: false,

list: true

},

{

key: 'color',

label: 'Color',

helpText: 'Choose the color of the products you want to import. Leave it empty if you do not want to filter.',

required: false,

list: true

},

{

key: 'other_tags',

label: 'Other Tags',

choices: ['yes', 'no'],

helpText: 'Do you want other tags to filter you products?',

required: true,

altersDynamicFields: true

},

function (z, bundle) {

if (bundle.inputData.other_tags == 'yes') {

return [{

key: 'tagname',

label: 'Tag Name',

helpText: 'Choose the name of the tag (or tags) you want to use for filter',

list: true,

dynamic: 'product_tags.value'

},

{

key: 'tagvalue',

label: 'Tag Value',

helpText: 'Choose the value of the tag (or tags) you want to use for filter',

list: true,

type: 'string'

}

];

}

return []

},

As you can see all inputFields are list:true so I treated them as arrays. 

First question

If a user only puts a field for example in brand, does bundle.inputData.brands counts as an array? To be sure I check if it’s an array and I treat it as a single variable if the check fails, but if you can assure me that when list:true the data is always an array I can avoid this check 

For each field I check with this piece of code 

if (tag.name == 'brand') {

if (bundle.inputData.brand !== undefined) {

if (Array.isArray(bundle.inputData.brand)) {

bundle.inputData.brand.forEach((brand) => {

passFilters = tag.value.value == brand

tagExists = true

})

} else {

passFilters = tag.value.value == bundle.inputData.brand

tagExists = true

}

}

}

Second question

When i make my test i define a bundle like this 

inputData: {

brand: ['people', 'moncler'],

tagname: ['gender', 'season', 'color-filter'],

tagvalue: ['donna', 'co', 'bianco'],

respect_all_filters: true,

},

And the code runs without problems. When i turn the zap on no error show and the zap doesn’t appear in the zap history. As if no product is found. 

It has to be noted that in the code I specify three distinct behaviours:

  • isLoadingSample == true; i pass a sample data 
  • isPopulatingDedupe == true; I pass an empty array cause I want the trigger to function the first time the polling starts
  • the normal polling, in which i made the first call to the api and the code should run smoothly 

Here’s the code to check this three states 

if (bundle.meta.isLoadingSample) {

params = {}

z.console.log("Trigger tested")

return new Array(sample)

}

else if (bundle.meta.isPopulatingDedupe) {

z.console.log("Zap is turning on")

return [];

}

else {

Last thing: in the code i use mongoose to save the date in which i made the API call because i can’t make a full exports of product before 20 minutes. So I pass with the request a lastUpdate so that the API can respond with the new products created between now and the date I pass. Can this create issues?

Sorry if this is unclear, i had to write this in a hurry and thanks to anyone that can help me 


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

2 replies

Userlevel 7
Badge +9

To provide your users with bulk export/import functionality Zapier offers a specialized feature called Transfer. To see how to enable support in your integration see this article.

Transfer is the correct way to implement any kind of bulk export.  To implement a regular polling trigger for a Zap workflow you’ll want to avoid the approach of circumventing the deduplication facility if your intent is to publish your integration in the Zapier App Directory or to share it with other users.  Zaps are workflows that are event based. A user turns them on and expects the new events/data created after the Zap is turned on to be processed.  They are not expecting a full export of data that may eat through their Zapier plan’s task limits or have other surprising effects.  (If you’re creating this for your own personal use, of course you’re free to build it however you like!)

Tactically/technically, I’m not sure why the poll isn’t yielding results. I’d maybe look at network or server logs to confirm how the request is actually getting constructed and what data is being returned.

Thank you for your response. I know that mine isn’t the proper way to bulk import but I just need to see if this can work. I read about transfer but it needs a published integration and to contact Zapier staff and I’m still experimenting with the platform, so right now I can’t test it.

Users of my zaps would need to contact my company anyway to set some things up (like oauth from the supplier they want to export product from) so they would be informed that the first zap would consume a good amount of they’re monthly plan. Even because the use case for my platform is to import a large amount of product and then keep them updated. I will eventually consider Transfer, but right now I need to know if this can work. Thank you for your advice nonetheless!

About the zap not working: can you explain to me how zapier forms bundle.inputData when fields are list: true? Are they always arrays, even if they’re empty or just with one value? Right now in tests I’m passing them as arrays and everything works. Even when the zap is on I read the right logs at the right time. I think the problem is in the filters and how these fields are treated. I’ll be glad if you could help me understand more. 

Thank you again, have a wonderful day!