How to optimize the script for thousands of API calls made one-by-one

49 views
Skip to first unread message

Ihor Stefurak

unread,
Jan 13, 2020, 7:29:25 AM1/13/20
to Google Apps Script Community
I have a function that takes an email address from a cell A1, makes URLfetch to my API and returns a response to B1. After a few hundred requests the function freezes.

How can I optimize the script for thousands of API calls without freezing? Any suggestions are welcomed.

The function:
function startProcess(input) {
     try {
       var response = UrlFetchApp.fetch("https://someapihere.com/&email=" +input);
       var json = response.getContentText();
       var data = JSON.parse(json);
       var deliverableResult = data.deliverable;
        if (deliverableResult == true) {
                 return [[deliverableResult]];
                }
       } catch (e) {
       return "the mail server doesn't respond";
     }
      Utilities.sleep(1500);

Romain Vialard

unread,
Jan 13, 2020, 8:48:18 AM1/13/20
to Google Apps Script Community
You can use the fetchAll() method to make hundreds of urlfetch calls simultaneously.

Ihor Stefurak

unread,
Jan 13, 2020, 9:48:19 AM1/13/20
to Google Apps Script Community
Thanks, Romain. I will try to rewrite the function and come back with questions if any.
Reply all
Reply to author
Forward
0 new messages