Api request in loop for

(Владимир Частоедов) #1

Hi!

I have an array with data and want to send a request if the value suits me. It is not possible to send several values at once, only one is triggered. Help, please!

Code:

for (var i = 0; i < contractors_spec.length; i++)
{
  if (contractors_spec[i].indexOf(product) != -1) 
        {
            url_get = url + "?respath=" + contractors_path[i] + "&order_id=" + order_id + "&product=" + article + "&count=" + count + "&adress=" + adress + "&time=" + time + "&contractor_id=" + contractors_id[i] + "&contractor_name=" + contractors_name[i] + "&order_path=" + order_path;    
            url_get = encodeURI(url_get);          
            
            var opts = {
            method: 'GET',
            url: url_get
            };

            utils.request(opts, function(err, resp, body) {
              if(err) { 
                return reject(err);
               }
              resolve(body);
            });

        }
}
(Karen Barker) #2

Hi there,

Unfortunately we’re unable to assist in writing custom code as JavaScript coding isn’t an area of support we cover.

However, the resolve function should only be called at the end of a script as calling this function passes the action and provides in your instance "body" as an output available in the rest of the flow. This function can only be called once during any script hence why you see the code stop running after the first succesful request is made.

I hope this helps. :slight_smile:

1 Like
(Владимир Частоедов) #3

Karen, Thank you! I will investigate this issue further :slight_smile: