Howdy,
so I am trying to sort an response of an products search API by a calculated value in a backend workflow with JavaScript via a Server Script from the Toolbox Plugin.
I managed to do this with one API, but struggling with another one where there is a nested array containing the necessary properties. This array always comes up empty or undefined in the server script. I could retrieve the values without problem on the client side. After hours of trying, I think this is either a limitation or a bug, but i might as well be doing it wrong
So this is how the json looks:
{
"brand": "Colgate",
"display_name": "Cepillo dental Colgate blister 4 unidades",
"price": 2.99,
"promotions": [
{
"description": "2ª ud al 50% dto. en selección colgate",
"only_club_dia": true,
"short_description": "SELECCIÓN COLGATE"
}
],
"units_in_stock": 102
}
The array in question is the "promotions"
array. Now in the client side script I am getting the contents of the description property of the only element in that array via this function:
//to get the promo description of an product
function getPromoDescription(item){
var myPromotions = item.get('_api_c2_promotions')
if (myPromotions == null) {
return null;
} else {
var len = myPromotions.length();
var myPromotionsList = myPromotions.get(0, len);
return(myPromotionsList[0].get('_api_c2_description'));
}
}
I followed the instructions from the toolbox help pages toolboxdocs server-script, which are great, but the results always come up undefined or with an empty array []
I currently think the problem is, that my "promotions"
array is another Bubble API Response Data Type, which is not loaded before sending the Server Script to the AWS instance and therefore never populated.
This is what it looks like in the API connector as a nested list in my search element.
So yeah, any help or hints much appreciated. Even if its just a confirmation, that this is a limitation or a bug, so I can stop trying this and try a different approach.
Thanks