Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Hitting unknown Tasks API quota

Hi,

Im using the Tasks API to create a dynamic tasks list. I get an error for a quota being exceeded after around 100 tasks.insert() calls.

  • I'm far below the quotas stated of 50k per day, and 60M per minute per user.
  • The runtime for the function is about 45 seconds.
  • tasks.item.length returns the correct number of tasks in the list until reaching 20, at which point adding new tasks will not increase the length, it seems to be capped at 20 for some reason. When checking the tasks list, there is clearly tasks being added and more than 20.
  • Some calls in between error messages go through, but often about 15% of calls fail in the batch of ~115
  • The tasks have three strings as fields
  • There is no other call to any function being made in the loop to call tasks.insert() where the error is being sent from
  • Setting a delay of .5 seconds fixes the issue
  • I only recently connected the Apps Script to my Google Cloud project
  • I only recently activated my full account on Google Cloud
  • There are no listed quotas that are being exceeded or even used besides the Google Tasks API listed in API's and Services

What quota am I hitting?

Error:

Error details: {"details":{"errors":[{"reason":"quotaExceeded","message":"Quota Exceeded","domain":"usageLimits"}],"code":403,"message":"Quota Exceeded"},"name":"GoogleJsonResponseException"}

0 1 198
1 REPLY 1

Hi @jjtjoseph,

Welcome to Google Cloud Community! 

You're getting a "Quota Exceeded" error, even though you haven't hit the known daily or per-minute limits for the Google Tasks API. This means you've likely triggered a hidden limit on how quickly you can send requests.

Here are some guides and workaround that might help:

  1. Reduce Batch Size: Instead of adding all 115 tasks at once, add them in smaller groups of 10-20. Pause briefly (half a second to a second) between each group. This slows down your requests and should fix the problem.
  2. Implement Exponential Backoff: To handle temporary service slowdowns, retry failed requests. Wait 1 second after the first failure, 2 seconds after the second, 4 seconds after the third, and so on. This prevents overloading the system and helps ensure all tasks complete eventually.

Sample code: 


function insertTasksWithBackoff(tasks) {
  const batchSize = 20;

  let delay = 1000; // Initial delay in milliseconds (1 second)
  for (let i = 0; i < tasks.length; i += batchSize) {
    const batch = tasks.slice(i, i + batchSize);

  try {
      // Your tasks.insert() call here, using the 'batch' array
      Utilities.sleep(delay); // Wait before the next batch

  delay = 1000; // Reset delay for the next batch
    } catch (error) {
    
  console.error("Error inserting tasks:", error);
      delay *= 2; // Double the delay on error

   i -= batchSize; // Retry the current batch
      Utilities.sleep(delay);
    }
  }
}

For your reference, you may refer to these documentations:

If you need further assistance into what specific implicit quota you're hitting, please feel free to reach out to our support team.


I hope the above information is helpful.

Top Labels in this Space