So I have written a Google App Script that will use the Admin SDK - Directory API to get a list of about 80 users. I then take each user and create a Email template with their directory data and then use the Gmail API to set their signature to a company default https://github.com/MrCaspan/GAS-Gmail-Signature-Templator if you care to look at the code. We run the script once an hour so that should be about 24 calls to the Directory API (No issues there) and about 1920 calls to the Gmail API in a 24 hour span (24 x 80 users) But I keep getting this error about 7PM every night and only for a few hours then it goes away
{
"error": {
"code": 429,
"message": "User-rate limit exceeded. Retry after 2021-10-21T23:45:03.158Z",
"errors": [
{
"message": "User-rate limit exceeded. Retry after 2021-10-21T23:45:03.158Z",
"domain": "global",
"reason": "rateLimitExceeded"
}
],
"status": "RESOURCE_EXHAUSTED"
}
}
When I look at my Google Cloud Project and look at my API usage its less then 0.01% of the daily limit. I cannot for the life of me figure out what is causing this issue. Because I am using Google App Script my script runs slow, maybe 180 seconds to finish for 80 users so its about a call to the API every 2 seconds so I cannot be overloading it. Also I can always run the script again and again and it always fails at the same point on the 75th API call 1 call the the Admin SDK and 73 calls successfully to the Gmail API then on the 75th I get this error. Strang thing is that it works perfectly fine all day with no issues its not till later at night that it happens.
Edit To Add: This happens always on the same users and normally happens after setting their signature 18 times and wont let me set it again for 8 hours. So I get a token from Google impersonating the user then set their signature.