Hello Community,
what might be the best approach to request a REST-API and from the response looping thru Ids to clone or update another REST-API. Before the target API is searched if Id is there. With timeout it's somewhat working but guess it's more elegant solution with async out there?
function init(unitGroupId, sourceDataToClone) {
if (typeof unitGroupId === "string") {
// Search Apaleo API for UnitGroupId
getApaleoUnitsByGroupId.trigger({
additionalScope: {
unitGroupId: unitGroupId,
},
onSuccess: function (data) {
let resultSet = data.units;
for (let i = 0; i < resultSet.length; i++) {
const apaleoUnitId = resultSet[i].id;
setTimeout(() => {
const result = searchProduct(apaleoUnitId);
const total = result.total;
if(total == 0) {
cloneProduct(source, apaleoUnitId);
}
}, i * 4000);
}
},
onError: function (error) {
console.log("ERROR query Apaleo API: " + error);
}
});
} else {
console.log("ERROR param unitGroupId not a string:" + unitGroupId);
}
}
Every hint or source to dive deeper is welcomed. The retool docs in this case could be a bit enriched.
rgds,
Andreas