Getting CS:GO player stats

Andrew picture Andrew · Jan 3, 2015 · Viewed 19.1k times · Source

How could I use the Steam Web API to get a player's stats, such as "Total Kills" or "Total Wins". Some sites that use these features include http://csgo-stats.com and http://csgo-stats.net. I have tried using http://api.steampowered.com/ISteamUserStats/GetGlobalStatsForGame/v0001/?format=xml&appid=730&count=1&name[0]=total_wins with no success. Where is the documentation for such statistics?

Answer

Andy picture Andy · Jan 4, 2015

I believe you are using the wrong API end point for this. Utilize the GetUserStatsForGame end point instead.

Your call will look like this:

http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=<<KEY>>&steamid=<<PROFILEID>>

You'll replace <<KEY>> with your API key and <<PROFILEID>> with the profile ID (not SteamID) of the user you are interested in. This value is the same one passed to you when you sign in via Valve's OpenID.

This will return a result similar to this:

{
    "playerstats": {
        "steamID": "7656-EDITED-OUT",
        "gameName": "ValveTestApp260",
        "stats": [
            {
                "name": "total_kills",
                "value": 110527
            },
            {
                "name": "total_deaths",
                "value": 95930
            },
            {
                "name": "total_time_played",
                "value": 5784386
            },
            {
                "name": "total_planted_bombs",
                "value": 2726
            },
            {
                "name": "total_defused_bombs",
                "value": 594
            },
            {
                "name": "total_wins",
                "value": 26937
            },
            ...
        ]
    }
}

You can see that you need to iterate through the ['playerstats']['stats'] element and look at the name attribute of each to find the stats you are looking for.