r/GoogleAppsScript • u/shadewood_mole • 2d ago
Question Problem accessing weather data from open-meteo.com using API call within Google Sheet with timed triggers
Hi,
I'm new to creating App scripts so please bear with me.
I've created a script to extract current weather details using a call to open-meteo.com and then write to a sheet.
When I test the script manually by pressing 'run' all works as expected, the script completes and the extracted data is written to the sheet.
So then I've set two timed triggers (6am and 6pm) to run the script.
However I get the following reports when these timers fire:
Exception: Request failed for https://api.open-meteo.com returned code 429. Truncated server response: {"error":true,"reason":"Daily API request limit exceeded. Please try again tomorrow."}
Reading the documentation there appears to be a 10,000 daily limit on the API calls.
So my assumption is that when the script is triggered there have already been too many calls from a particular Google address on that day?
I guess the manual run is treated differently for some reason?
Is this a correct assumption?
If that is the case, is there some way of making the call that will work without hitting the API call limit?
Any help welcome.
Thanks
2
u/Unusual_Analyst3648 2d ago
Hello,
Two free alternatives:
WeatherAPI.com
OpenWeatherMap.org
Alternatively, you can modify your code to include a loop that retries up to 5 times in the event of a 429 error.
Google has thousands of IP addresses. If you make a request and it fails (with a 429 error), waiting a few seconds and trying again will often route your request through a different Google server, one that may not be blocked.
2
u/No-Sheepherder7116 2d ago edited 2d ago
Yes, your assumption is basically right, with one important detail: that daily limit is per IP address, not per account.
Apps Script's UrlFetchApp does not go out from your own IP. It runs on shared Google infrastructure, so your two calls a day are sharing that day's quota with other people's scripts that happen to use the same outgoing IP. That is why it can already be used up by 6am, and why a manual run later can work — you are likely hitting a different outgoing IP, or a time when that IP's quota has not been used up yet.
A quick retry loop alone is not a reliable fix. If that IP's quota is used up for the day, retrying a few seconds later will just get the same 429, and it adds more calls. A retry with a delay can sometimes help if you land on a different outgoing IP, but do not depend on it.
What I would do:
Make exactly one call per run, and only ask for the current fields you actually need. Do not call it in a loop, once per row, or once per cell.
Move the triggers off the hour, for example 6:20am and 6:20pm instead of 6:00. A lot of time triggers fire on the hour, so that is the busiest time for the shared quota. Time triggers are approximate anyway, so this does not change when the sheet is updated in any meaningful way.
Save the last good result, and fall back to it on a 429 instead of failing or writing a blank or error row. This is the part that makes the twice-daily sheet usable even when a run hits the limit.
Here is a drop-in pattern for the fetch part. Keep your existing request, and only write to the sheet after this returns data:
Then in your main function, call that, and only write the values to the sheet if it returns something. If it falls back to the saved result, add a note in the sheet like "cached from earlier run" so you know that row is not fresh.
If you want a long-term fix rather than working around the shared quota, switch to a weather provider that gives you a personal API key. Then the quota is tied to your key, not to a shared outgoing IP, so other Apps Script users cannot use it up.