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 n{
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 n]
},
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: a'gender', 'season', 'color-filter'],
tagvalue: g'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