Home > Enterprise >  Google Sheets error - Service invoked too many times for one day: urlfetch
Google Sheets error - Service invoked too many times for one day: urlfetch

Time:12-27

I have problem with my function in Google Sheets. I am getting every day this error: "Exception: Service invoked too many times for one day: urlfetch." I have about 1000 urls in document. I am looked for solution at google. I find some topics where is recommended to add cache to function but I dont know how to do it. Does somebody have any idea? My function:

function ImportCeny(url, HTMLClass) { 
  var output = ''; 
  var fetchedUrl = UrlFetchApp.fetch(url, {muteHttpExceptions: true}); 
  if (fetchedUrl) { 
    var html = fetchedUrl.getContentText(); 
  } 
  // Grace period to avoid call limit 
  Utilities.sleep(1000); 
  var priceposition = html.search(HTMLClass);
  return html.slice(priceposition,priceposition   70).match(/(-\d |\d )(,\d )*(\.\d )*/g); 
}

CodePudding user response:

You may try to add a randomly generated number, for example 6 digits and add this number to the URL as a parameter each time before calling "UrlFetchApp"

i.e.;

url = url & "?t=458796"

CodePudding user response:

You can certainly use Utilities.sleep() to force the program to stop for some time before making the next call. However, using the built-in Cache class (you can see the docs here) is much more suitable as it is specially designed for these scenarios. So, if you wanted to leave one second you could replace:

Utilities.sleep(1000); //In milliseconds

with

var cache = CacheService.getScriptCache(); //Create a cache instance
cache.put("my_content", html, 1); // In seconds
  • Related