WebAPI

From Team Fortress Wiki
Revision as of 10:06, 2 July 2010 by BogeymanEST (talk | contribs) (Return Value)
Jump to: navigation, search

The WebAPI calls allow you to retrieve information from the item system in Team Fortress 2. Each call requires a valid API Key to function. You can get your own API Key here.

Format differences

Every method can return its results in 3 different formats: JSON, XML, and VDF. Each format represents the data described herein differently:

  • JSON
    • The API contains an object containing an object named "result".
    • Arrays are represented as an array with the name of the type of the objects in the array (ie. an object named "items" containing an array of objects of type "item" would be represented as an object named "items" containing an array named "item" containing several objects following the "item" structure).
  • XML
    • XML Attributes are not used.
    • Arrays are represented as a series of sub-elements in the containing element of the type of the array.
  • VDF (Valve Data Format)
    • This is Valve's internal data format, seen in TF2's "scripts" folder (available in "team fortress 2 client content.gcf"). GetSchema returns data similar to "items/items_game.txt" (although qualities are not expanded into objects with a "value" field).
    • It appears to be undocumented, but it works similarly to JSON's objects:
      • A member is represented by a quoted string, followed by a newline and an open brace.
      • A value is represented as a key-value pair of quoted strings on the same line separated by a tab character. Each sub-object is indented by one tab character.
    • Arrays in the data are represented as a VDF array with the name of the type of the objects in the array, with a VDF array being an object with each item being prefixed with its numeric key as a quoted string.

GetSchema (v0001)

Example URL: http://api.steampowered.com/ITFItems_440/GetSchema/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Arguments

None

Return Value

Returns the item schema for the current build of Team Fortress 2, structured as follows:

{ 
  "result": 
  { 
      "status": 1, 
      "qualities": 
      { 
          "normal": 0, 
          "common": 1, 
          "rare": 2, 
          "unique": 3, 
          "community": 7, 
          "developer": 8, 
          "selfmade": 9 
      }, 
      "items": 
      { 
          "item": 
          [ 
              { 
                  "name": "TF_WEAPON_BAT", 
                  "defindex": 0, 
                  "item_class": "tf_weapon_bat", 
                  "item_type_name": "#TF_Weapon_Bat", 
                  "item_name": "#TF_Weapon_Bat", 
                  "item_slot": "melee", 
                  "item_quality": 0, 
                  "image_inventory": "backpack\/weapons\/c_models\/c_bat", 
                  "model_player": "models\/weapons\/w_models\/w_bat.mdl" 
              }, 
          ] 
      }, 
      "attributes": 
      { 
          "attribute": 
          [ 
              { 
                  "name": "damage penalty", 
                  "defindex": 1, 
                  "attribute_class": "mult_dmg", 
                  "min_value": 0.950000, 
                  "max_value": 0.850000, 
                  "description_string": "#Attrib_DamageDone_Negative", 
                  "description_format": "value_is_percentage", 
                  "effect_type": "negative" 
              }, 
          ] 
      } 
  } 
} 


The defindex fields in items and attributes corresponds with the same field in the GetPlayerItems calls.

GetPlayerItems (v0001)

The GetPlayerItems call returns a the items for the player specified. If a player has their Steam community profile set to Private you will not be able to retrieve their items.

Example URL: http://api.steampowered.com/ITFItems_440/GetPlayerItems/v0001/?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&steamID=12345678

Arguments

SteamID

Return Value

A list of the player's items is returned, as follows:

{ 
  "result": { 
      "status": 1, 
      "items": { 
          "item": [ 
              { 
                  "id": 827, 
                  "defindex": 166, 
                  "level": 5, 
                  "quality": 3, 
                  "inventory": 2147483650, 
                  "quantity": 1, 
                  "attributes": 
                  { 
                      "attribute": [ 
                          { 
                              "defindex": 143, 
                              "value": 1272326400.000000 
                          } 
                      ] 
                  } 
              }, 
          ] 
      }
  } 
} 

If a player's profile is set to Private the status field will be set to 15 (Access Denied) and there will be no items field.