Home > Mobile >  Why is Google Apps Script giving me this UrlFetchApp script code 429?
Why is Google Apps Script giving me this UrlFetchApp script code 429?

Time:09-17

I have been having a strange error that I have been going in circles trying to figure out. I decided to learn some JavaScript/google apps script to parse some information from an api of a game I play. I followed a bunch of tutorials and searched google and Stack Overflow for solutions but none have worked. I think I've narrowed it down to one particular Method: the "UrlFetchApp."

Right now I'm simply trying to grab some JSON data from the API and display it in the log window.

I keep getting this:

[21-09-13 09:01:40:770 EDT] Exception: Request failed for https://api.guildwars2.com returned code 429. Truncated server response: {"text":"too many requests"} (use muteHttpExceptions option to examine full response)
    at getRequest(Untitled:4:30)

Now here's the strange part, I ran the script from my phone at work to test some theories out and got this:

[21-09-13 09:02:20:943 EDT] {
  "name": "Abomination Hammer",
  "type": "Weapon",
  "level": 0,
  "rarity": "Fine",
  "vendor_value": 0,
  "default_skin": 5014,
  "game_types": [
    "Activity",
    "Wvw",
    "Dungeon",
    "Pve"
  ],
  "flags": [
    "NoSell",
    "SoulbindOnAcquire",
    "SoulBindOnUse"
  ],
  "restrictions": [],
  "id": 15,
  "chat_link": "[&AgEPAAAA]",
  "icon": "https://render.guildwars2.com/file/E8507FFB6CF3C9094A69956344CEDBD9B47D95B6/434872.png",
  "details": {
    "type": "Hammer",
    "damage_type": "Physical",
    "min_power": 146,
    "max_power": 165,
    "defense": 0,
    "infusion_slots": [],
    "attribute_adjustment": 20.736,
    "infix_upgrade": {
      "id": 112,
      "attributes": []
    },
    "secondary_suffix_item_id": ""
  }
}

I doubt it's the code now. That is what was supposed to be returned. It's the same code unedited and ran multiple times on both my phone and computer and the results are always the same.

Here's the line of code I wrote:

function getRequest() {

  var response = UrlFetchApp.fetch('https://api.guildwars2.com/v2/items/15');
     
     Logger.log(response)
}

Can anyone help? I'm really frustrated now.

CodePudding user response:

Response status code 429 shows when a user sent too many requests in a given amount of time. Based on the documentation of Rate Limiting in Guild Wars the rate limit is tracked per-IP and the maximum request per minute is 600.

In your script, you can confirm the rate limit by printing the header by using response.getAllHeaders() or response.getHeaders() and you will see x-rate-limit-limit=600.

X-Rate-Limit-Limit is the maximum number of requests that may be issued within a minute. This is a static value doesn’t contain count for requests you have already sent.

Usually, 429 status code includes Retry-After header. This indicates how long a user must wait before making a new request. You can also view this by printing the header.

If the Retry-After is not included in the headers, you can follow Elchanan shuky Shukrun comment above to use VPN since the rate limit is tracked per IP. You can also use the Guild Wars forum and create a post for a possible bug.

Reference:

  • Related