phpsteam

Get CSGO inventory with steam API


I need to get csgo inventory with steam API. I use this url

https://api.steampowered.com/IEconItems_730/GetPlayerItems/v1key=$api_key&steamids=$steamid

and I use this URL for access to all csgo items.

https://api.steampowered.com/IEconItems_730/GetSchema/v2

problem 1, is I can't understand the returned value in first URL. There is no item name, image and ... . This is how it will return:

            "id": 547938992,
            "original_id": 547938992,
            "defindex": 13,
            "level": 1,
            "quality": 4,
            "inventory": 53,
            "quantity": 1,
            "rarity": 1,
            "attributes":

problem 2, when is use second URL to get all of csgo skins. it just returns vanilla skins. how can i get full skins like other websites : opskins , bitskins, csgolounge and .... .

I know there is alot of question like this in Stack Overflow but none of them answer the way I can understand.


Solution

  • For my project I use another url for steam's API,

    "http://steamcommunity.com/profiles/*insert steamId*/inventory/json/730/2"

    You can try to use your steamID and paste it into your browser and you will see how the response looks like. This is what you will be working with.

    If you make a request with this url you will get a response with a json object which have two parts. One part is called rgInventory(ie. data.rgInventory)and contains ids for each skin in the users csgo-inventory. The second part is called rgDescriptions(ie. data.rgDescriptions) and contains info/name/img url for each skin. To add the info to the skins the user have in rgInventory you need to compare the classId for each item on both the rgInventoryand rgDescriptions. The classIdis the id which decide which type of weapon it is, therefore the classid is not unique.

    So what Im doing is using two for-loops, and compares the ids so I can add the item_url, market_name etc. To the rgInventory array which I then I send away as the callback. Like this (javascript):

                var ids = getID(data.rgInventory);
                var item = getItems(data.rgDescriptions);
    
                for (var i = 0; i < ids.length; i++) {
                    for (var k = 0; k < item.length; k++) {
                        if (ids[i].classid == item[k].classid) {
                            ids[i].market_name = item[k].market_name;
                            ids[i].icon_url = item[k].icon_url;
                            ids[i].tradable = item[k].tradable;
                        }
                    }
                }
    

    So if the classids of both items is the same I will add the information I want to the variable "ids" which in this case is a copy of rgInventory. When the for-loops are done I send away the ids-variable as my callback.

    Feel free to ask questions, and sorry if this is confusing. Remember to type the url I linked with your steam-profile in your browser and see the result.

    Hope it helps!