Meltinglava
Meltinglava

Reputation: 349

JSON.parse returning undefined object

Blizzard just shut down their old API, and made a change so you need an apikey. I changed the URL to the new api, and added the API key. I know that the URL is valid.

var toonJSON = UrlFetchApp.fetch("eu.api.battle.net/wow/character/"+toonRealm+"/"+toonName+"?fields=items,statistics,progression,talents,audit&apikey="+apiKey, {muteHttpExceptions: true})
var toon = JSON.parse(toonJSON.getContentText())

JSON.pase returns just an empty object

return toon.toSorce() // retuned ({})

I used alot of time to see if i could find the problem. have come up empty. Think it has something to do with the "responce headers".

Responce headers: http://pastebin.com/t30giRK1 (i got them from dev.battle.net (blizzards api site) JSON: http://pastebin.com/CPam4syG

Upvotes: 0

Views: 555

Answers (3)

Alexander Melnik
Alexander Melnik

Reputation: 1

was same problem, this works for me (dont forget to paste your key)

var toonJSON = UrlFetchApp.fetch("https://eu.api.battle.net/wow/character/"+toonRealm+"/"+toonName+"?fields=items%2Cstatistics%2Cprogression%2Caudit&locale=en_GB&apikey= ... ")

Upvotes: 0

Meltinglava
Meltinglava

Reputation: 349

So i found the problems:

  1. I needed https:// in the URL since i found after some hours that i had an SSL error
  2. If you just use toString instead of getContentText it works. Thow why getContentText do not work, i am not sure of.

Upvotes: 0

Napoleon
Napoleon

Reputation: 340

I think it is the code you're using. I was able to Parse it by opening the raw url of your pastebin JSON http://pastebin.com/raw/CPam4syG And using the following code

var text = document.getElementsByTagName('pre')[0].innerHTML;
var parse = JSON.parse(text);

So to conclude I think it is the UrlFetchApp.fetch that's returning {}

Upvotes: 0

Related Questions