google-apps-scripthttp-status-code-429coingecko

Why did I suddenly get "You've exceeded the Rate Limit" error?


Problem:

Environment:

Error Message:

Exception: Request failed for https://api.coingecko.com returned code 429. Truncated server response: {"status":{"error_code":429, "error_message": "You've exceeded the Rate Limit. Please visit https://www.coingecko.com/en/api/pricing to subscribe to ... (use the muteHttpExceptions option to examine the full response)

Code:

function test() {
  const URL = 'https://api.coingecko.com/api/v3/coins/bitcoin'
  
  Utilities.sleep(10000)
  const fetchedData1 = UrlFetchApp.fetch(url)
  console.log(fetchedData1)

  Utilities.sleep(10000)
  const fetchedData2 = UrlFetchApp.fetch(url)
  console.log(fetchedData2)
  
}


Solution

  • Try adding Utilities.sleep(10000); before CoinGecko.tryCatch(i); to reduce the calls rate to the API.

    Use trial and error to find the "optimal value" for the Utilities.sleep parameter and use together with an advanced algorithm like exponential backoff to handle Google Apps Script performance variations.

    Related