Hello,
I want to use python to play around with auction house data and display it in various ways by a localhost website, however I have trouble fetching the auction house data - help is very much appreciated!
My knowledge of API’s are quite slim, so consider me a total noob!!
I use python and what I’ve tried to do so far is doing the following call:
ahdata = requests.get(“https: //eu api battle net/wow/auction/data/outland?locale=en_EU&apikey=MYKEYHERE”)
(can’t post links, but you get the idea)
print(ahdata)
I try to print out the request to see if it went through, however nothing ever happens.
Apologies if this question has been answered before, but I’ve spent hours trying to figure out what I’m doing wrong and I’m lost.
Thanks!
That is completely wrong, there is no queryString option apikey
, you need an access token to consume API endpoints.
The correct call would be https://{region}.api.blizzard.com/wow/auction/data/{realm}?locale={locale}&access_token={token}
.
Also note there is no server named outland, to fetch a list of available realms you can use this endpoint: https://{region}.api.blizzard.com/data/wow/realm/index?namespace=dynamic-{region}&locale=en_US&access_token={token}
. There is no AH data available for Classic at the moment.
To obtain a valid access token you must use the client_credentials OAuth2 flow. More details on that here and here.
Thanks for your help, much appreciated.
I looked at an older post https://us.battle.net/forums/en/bnet/topic/20742214372 where an api key was needed, which is why I thought that was the way to go! Is it no longer possible to do it this way?
Oh I see. That was how the old API authentication used to work. That does not work anymore, you have to use the methods described in the official API docs.
Also note an access token only lasts for 8-24 hours. You must keep track of the token duration and generate a new one as needed.
I added a python sample to this topic. There are other ways to integrate OAuth2 in python but this will create you an access_token.
1 Like
I got it working thanks to your sample - thank you!
Be careful - AH data is very large and you can lose your connection or broke your script.
You need to do somethink like this:
(idk how to make spaces)
Code
import requests
import json
auction_data = requests.get(ah_url, stream=True)
with open(‘ah_data.json’, ‘w’, encoding=‘utf-8’) as f:
____for line in auction_data.iter_lines():
________f.write(line.decode(‘utf-8’))
with open(‘ah_data.json’, ‘r’, encoding=‘utf-8’) as f:
____json_data = json.load(f)
After this, you can access all yours auction data from json_data