Mattia
Mattia

Reputation: 329

Cannot find a way to catch the Usage limit Reach on Google Spreadsheet API with node module google-spreadsheet

I'm using the module google-spreadsheet (NPM) for NodeJS, but i've a questions: How can i check how many requests i've and how can i handle the usage limit reach?

I'm trying with this code to try it:

try {
    for (let i = 0; i <= 305; i++) {
        await sheet.getRows(mySHeet);
        console.log("test: " + (i + 1));
    }
} catch (err) {
    console.log("Error:", err)
}

But after 300 requests (the limit is 300 per minute) the app simply crashes with error code 1 without giving anything and it does not enter in the catch.

So if the APP reach the Google API limits, it crashes and exit. I've also handled the errors with process but it doesn't change anything: (with unhandledRejection and uncaughtException).

Thank you!

Upvotes: 0

Views: 254

Answers (1)

ziganotschka
ziganotschka

Reputation: 26836

While I do not work with NPM,

I can advice you to review the Google Sheets API Usage Limits.

As you see,

Sheets API Usage Limits are 100 requests per 100 seconds per user.

Temporary bursts are allowed (this is why you might get away with 300 requests per minute), but you are stretching it.

What you can do:

  • Try to request more quota from GCP, as explained in the documentation
  • Perform batchrequests to reduce the number of calls to the API
  • Implement exponential backoff algorithms that implement waiting times between requests to avoid the rate limit, see [here](exponential backoff) for more details.

Upvotes: 1

Related Questions