Async Queries to REST-API > Best Practices

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
                  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 =;

                              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.



Hi @Kiteman

Thanks for reaching out! Generally speaking for any sort of looping in Retool, we tend to recommend checking out this doc

In your example, is getApaleoUnitsByGroupId the second API? Are you hitting rate limits on your api? This post and this post could be helpful :slightly_smiling_face: