Grax.9204:

Hello there

I’m having an issue retrieving data from the authenticated API endpoints in a google spreadsheet.

Here’s the code that causes issues:


var url = 'https://api.guildwars2.com/v2/account/bank?access_token=' + apiKey;
var response = UrlFetchApp.fetch(url);

The error I get: “ErrBadParam”.

When using the exact same URL as well as API-Key in my browser, I get the expected JSON result.
Accessing unauthenticated endpoints with the same code, without the access token, works as well.

What am I missing?

DragonHeart.7201:

You might have to set the headers correctly to fetch the data.

var options = { };
options[“method”] = “GET”;
options[“contentType”] = “application/json”;

var response = UrlFetchApp.fetch(url, options);

Not sure if this will solve your issue, worth a shot.

Grax.9204:

Thanks for the tip.

Here’s what I tried:


var apiKey = "9EBFF0A1-988B-9C41-8E52-DFE622E774967324E1F7-AAA2-4837-974A-B42B312263B6";
var url = 'https://api.guildwars2.com/v2/account/bank?access_token=' + apiKey;
  
var options = {
  "method": "GET",
  "contentType": "application/json",
  "muteHttpExceptions": true
};
var response = UrlFetchApp.fetch(url, options);

Same result, the response I get is “ErrBadParam”.

SlippyCheeze.5483:

Your issue is something specific in the Google Apps script, rather than the URL; since you supplied the API key I was able to verify that it works, and returns data, manually.

Have you tried dumping the body of the response object, which may contain more details? Anyway, ultimately, this is a “local code” issue, not an API issue. Sorry.