Spending your in-game gold on shiny trinkets
Now that we have the basics down after getting a list of heroes using GetHeroes
, let's apply the same concepts to an API call to GetGameItems
. After getting the data back, we can play around with the list of items and display them according to some of their properties!
The basic GET request is made to the following URL. Again, substitute APIKEY
with your own. The common options are still available, and we can specify a language so that we'll also get a localized_name
in our response, so we can substitute LANGCODE
with the language code we want. Let's use es_es
for Spanish. Our response JSON is below the URL.
https://api.steampowered.com/IEconDOTA2_570/GetGameItems/V001/?key=APIKEY&language=LANGCODE
Like the response from GetHeroes
, we have another fairly straightforward list of items that we can buy in the game.
result
items
: An array of the item objects in the gameid
: The unique ID for the itemname
: Code name for the itemcost
: The cost in gold of the itemsecret_shop
: Indicates if the item is available in the secret shop (1/true if available, and 0/false if not available)side_shop
: Indicates if the item is available in the side shop in-game (1/true if available, and 0/false if not available)recipe
: Indicates if the item is a recipe (1/true if it is a recipe, and 0/false if not)localized_name
: As with GetHeroes
, if a language is specified in the parameters, then the in-game name in the specified language is included in our response
Like the heroes, items have images that we can display. We can get high-quality images from the Steam servers for our items using the following URL. We can replace ITEMNAME
with the name of the item obtained from the response to the GetGameItems
call, but with the prefix item_
dropped. For example, to get the image for the Divine Rapier, we use rapier
instead of item_rapier
.
http://cdn.dota2.com/apps/dota2/images/items/ITEMNAME_lg.png
Now that we have a URL for item images and our JSON response, we can do something akin to what we did for displaying the hero images in the Hero Details section. With a few modifications to our sample code, we can create a list of items that cost at least 1000 gold to buy and are available in the secret shop, and display their Spanish name and the corresponding image. Your test
page should have the corresponding handlebars for displaying list items. Again, we parse the response using JSON.parse(body)
, then create an array of items that pass our specification (available in the secret shop and at least 1000 gold to buy) by using objects holding the localized name and an HTML img
tag. We then use Handlebars to display the list on our page. The result is shown below. You should prepare to have a good amount of gold if you want to buy these items in the secret shop!
The note in the Hero Details section can also apply here. Again, the list of items is infrequently updated, so it doesn't make much sense to make an API call every time the page is loaded, since it's not likely the list of items will be updated every minute. To avoid making unnecessary API calls, we can again make a single call outside of the app.get()
function that is only run once every time the server is started, then store the results of that call in a variable for use, or we can save the results from the API call as a separate JSON file and use that data for our pages.
Now that we have the ability to get both hero and item data from the Dota 2 web API, we can combine these with match details, much like existing web applications for tracking match statistics! The basic ideas behind what we're doing can be used to recreate your favorite Dota-related website of your choice or create your own Dota-related web app.