Getting information about a specific match, so you can show off your 900 GPM on Gyrocopter and 3 divine rapiers
Let's say you just played an awesome game of Dota, where you had great itemization, good farm, and a nice kill/death ratio, and you'd like to get the data so that you can use it on a webpage down the line. We can do that by making a call to the Dota 2 web API and getting the match details. We can also combine our previous calls to GetHeroes
and GetGameItems
with the match details to display the match details in a manner that's not totally hideous.
GetMatchDetails
has the common options (discussed in Getting Started) as well as a parameter for match ID: match_id=MATCHID
(as an ID), where we replace MATCHID
with the ID of the match we would like to see. As noted previously, replace APIKEY
with your own API key or the variable storing it. The general format is a GET request as follows:
https://api.steampowered.com/IDOTA2Match_570/GetMatchDetails/V001/?match_id=MATCHID&key=APIKEY
For our example, we'll use the following match ID: 1973457695
. For simplicity, this is a public ranked all-pick match, without a pick/ban series. We'll make a GET request to the previous URL with the substituted match ID and API key. The result is a pretty hefty JSON response:
There's a lot going on in our JSON response, so here's a breakdown of the response that we get and what it all means:
result
players
: List of players in the matchaccount_id
: 32-bit Steam account IDplayer_slot
: 8-bit unsigned integer representing the player's team and position in the team (see below)hero_id
: The ID of the hero played by the player; corresponds to the id
from GetHeroes
, covered in the Hero Details sectionitem_0
: The ID of the top-left inventory item (see Item Details)item_1
: The ID of the top-center inventory itemitem_2
: The ID of the top-right inventory itemitem_3
: The ID of the bottom-left inventory itemitem_4
: The ID of the bottom-center inventory itemitem_5
: The ID of the bottom-right inventory itemkills
: The number of kills made by this playerdeaths
: The number of deaths for this playerassists
: The number of kill assists made by this playerleaver_status
: game abandoning or disconnect from game for this player (see below)status
: Status of the API call.count
: The total number of heroes in the list.gold
: Gold remaining for the player at the end of the matchlast_hits
: Last hits the player had during the matchdenies
: Number of denies made by the player during the matchgold_per_min
: The player's overall gold per minutexp_per_min
: The player's overall experience per minutegold_spent
: The amount of gold the player spent during the matchhero_damage
: The amount of damage the player dealt to heroes during the matchtower_damage
: The amount of damage the player dealt to towers during the matchhero_healing
: The amount of health the player healed for heroeslevel
: The player's level at the end of the matchability_upgrades
: An array detailing the order in which the player's ability points were spentability
: The numeric ID corresponding to the ability that was upgradedtime
: The time that the ability point was spent, in secondslevel
: The level of the hero when the ability was upgradedadditional_units
: Details about additional units controlled by the player (e.g., Lone Druid's spirit bear)unitname
: Name of the additional unititem_0
: The ID of the top-left inventory item (see Item Details)item_1
: The ID of the top-center inventory itemitem_2
: The ID of the top-right inventory itemitem_3
: The ID of the bottom-left inventory itemitem_4
: The ID of the bottom-center inventory itemitem_5
: The ID of the bottom-right inventory itemradiant_win
: The winner of the match; 1 is true for Radiant, and 0 is false, meaning that the Dire wonduration
: The length of the match, in secondsstart_time
: Unix timestamp of when the match began (since Jan 1, 1970)match_id
: The match's unique IDmatch_seq_num
: A sequence number representing the order in which matches were recordedtower_status_radiant
: A 16-bit unsigned integer representing the status of the towers for the Radiant (see below)tower_status_dire
: A 16-bit unsigned integer representing the status of the towers for the Dire (see below)barracks_status_radiant
: An 8-bit unsigned integer representing the status of the barracks for the Radiant (see below)barracks_status_dire
: An 8-bit unsigned integer representing the status of the barracks for the Dire (see below)cluster
: Used for downloading replays of matches (see below as well as replay_salt
discussion below)first_blood_time
: The time in seconds at which first blood occurredreplay_salt
: Used for downloading replays (as of this writing, this has been removed from the API, according to this post on the Dota 2 dev forums; see below)lobby_type
: The lobby type (see below)human_players
: The number of human players in the matchleagueid
: The league that this match was a part of (covered in Tournament Details)positive_votes
: The number of thumbs up the game has receivednegative_votes
: The number of thumbs down the game has receivedgame_mode
: A number representing the game mode (see below)engine
: 0 for Source 1, and 1 for Source 2radiant_team_id
: Team ID for the Radiant (only included if there were teams applied to the Radiant and Dire, such as in a league match in a private lobby)radiant_name
: Team name for the Radiant (only included if there were teams applied to the Radiant and Dire)radiant_logo
: The Radiant team's logo (only included if there were teams applied to the Radiant and Dire)radiant_team_complete
: 1 if all players on the Radiant belong to this team; 0 if a stand-in player was used (only included if there were teams applied to the Radiant and Dire)dire_team_id
: Team ID for the Dire (only included if there were teams applied to the Radiant and Dire)dire_name
: Team name for the Dire (only included if there were teams applied to the Radiant and Dire)dire_logo
: The Dire team's logo (only included if there were teams applied to the Radiant and Dire)dire_team_complete
1 if all players on the Dire belong to this team; 0 if a stand-in player was used (only included if there were teams applied to the Radiant and Dire)radiant_captain
: 32-bit Steam ID of the player who was the captain of the Radiant for this match (only included if there were teams applied to the Radiant and Dire)dire_captain
: 32-bit Steam ID of the player who was the captain of the Dire for this match (only included if there were teams applied to the Radiant and Dire)picks_bans
An array of the picks and bans in a match, if the game mode is captains modeis_pick
: If the item is a pick (1 for true) or a ban (0 for false)hero_id
: The hero IDteam
: The team that chose the pick/ban; 0 for the Radiant, and 1 for the Direorder
: The order position for the pick/ban (0 - 19)
The player slot is represented by an 8-bit unsigned integer. The first bit represents the player's team: if Radiant, then the first bit is 0/false; if Dire, then the first bit is 1/true. The last three bits represent the player's position in the team (decimal 0 - 4). If a player's player_slot
is 129 in decimal (which is 10000001 in binary), then they are the second player on the Dire team.
Dota has a system that punishes players that frequently abandon games, as abandoning or disconnecting from games will have a negative impact on your teammates.
The tower status is represented by a 16-bit unsigned integer; the rightmost 11 bits represent individual towers for the team. The rightmost 11 bits represent the towers in the following order: ancient top tower, ancient bottom tower, bottom tier 3, bottom tier 2, bottom tier 1, middle tier 3, middle tier 2, middle tier 1, top tier 3, top tier 3, and top tier 1. For example, if the tower_status_radiant
is 1572 in decimal (as in the example), then this is 0000011000100100 in binary. The first five bits do not matter, so we have 11000100100. This means that the Radiant still had their ancient top and bottom towers, as well as their middle and top tier 3 towers.
Each team's barracks status is represented by an 8-bit unsigned integer; the rightmost 6 bits represent individual barracks for the team. The rightmost 6 bits represent the barracks in the following order: bottom ranged, bottom melee, middle ranged, middle melee, top ranged, and top melee. For example, if the barracks_status_dire
is 32 (as in the example), then this is 00100000 in binary. The first two bits do not matter, so we have 100000. This means that the Dire still had their bottom ranged barracks at the end of the game, but all others were destroyed.
The cluster indicates the general server the match was played on. This value could be used to download replays, but the ability to download replays has since been removed with the removal of the replay_salt
field from the API (see below). The match in our example was played on a Europe West server.
According to this post on the Dota 2 dev forum, the replay_salt
field has been removed due to privacy issues. Therefore, the previous method of downloading replays is not available.
Previously, replays were downloaded using the cluster
, match_id
, and replay_salt
using the following URL (replace CLUSTER
, MATCHID
, and REPLAYSALT
accordingly):
http://replayCLUSTER.valve.net/570/MATCHID_REPLAYSALT.dem.bz2
Indicates the type of lobby, such as public, practice, ranked, etc. The match in our example was a ranked match.
This field gives additional information about the game mode, such as if a match was single draft, all random, or all pick. The match in our example is a ranked all pick match.
Now that we're able to pull match details using an API call, we can attempt to display it in a manner that's easily digestible for users.
This is a fairly brief match summary that displays the match ID, start time, duration, and the winner, as well as the hero portraits for each team. There are two separate functions, convertUnixTime()
and findHero()
, which are left as exercises for the reader. This example uses Node.js, Express, and Handlebars.
Match ID: 1973457695
Match start: Tue Dec 01 2015 23:14:59 GMT+0000 (Coordinated Universal Time)
Radiant wins!
Duration: 72min 16sec
Radiant
Dire