The 'api' is a new tool made by Torn you can use to build your own applications / extensions for Torn. The info on this page is copied directly from the api's site (with info added from several people spread out over Torn ), so make sure to read it carefully before using the api.
To start using the api go here and then click on the 'try it' button. Then you can fill in your api key at the top, this can be found under the 'api key' section on this page. Then select for example the user section, fill in your id and a selection of your choice.
If you do not know the selections and they are not displayed on the 'try it' section, you can always go to http://api.torn.com/user/?selections=lookup&key=apikeyhere to see what the possible selections are.
Firstly what does API stand for? It stands for Application Programming Interface. Now you may be wondering, what exactly is an API? A full definition can be found here, but that isn't really important, what's more important is what it can do, which you can find in the details section of this page.
The goal of the Torn API is to provide a fully supported and read-only method for players to pull useful information from Torn about their player, faction, or company. This can be used individually to retrieve information about your account, or you can build a website that the entire community can use to do interesting things with the data exposed via the API.
Whether you're making a browser extension to aid factions during wartime, a mobile application to offer instant notifications, or a website to track data for graphing - the possibilities are endless - simply using the 8 character API keys. We encourage you to be creative, building features and tools that expand Torn's gameplay and enjoyment.
The API system is new, so changes and additions will happen. Suggestions can be posted in Torn's API forum and any issues you find can be reported in Torn's Bugs & Issues forum; they'll be fixed promptly.
This system has been developed so that you only ever need to request an API key from the user. All of the user's information can be obtained with just their key, there shouldn't be any requirement to ask for a name or user ID. Torn passwords should never be requested from any users, ever.
You must keep keys, and the data obtained from them, securely protected and confidential unless permitted by the key owner. By accepting other user's keys, they are placing their trust in you - do not exploit this. We will permanently ban offending applications from accessing the API at a moment's notice.
We respectfully request that you follow Torn's no-advertising policy when building websites or applications that use our API system to ensure optimal user experience, however, exceptions can be made. Please contact us if you would like to advertise, accept voluntary real-money donations or charge users for usage.
Please make sure your scripts are optimised to retrieve only the information required for the specific request they're making. They should be retrieving as little information as possible; this will improve loading time and reduce stress on Torn's servers.
We understand that crafting an API system for Torn could give some users an unfair advantage. We want the system to expand & enhance gameplay rather than giving users an advantage which makes it easier to compete against others. We have taken this into account during development, but we will be listening to feedback and making any appropriate changes that are required.
One measure that has been implemented is the delay to the stock market API by fifteen minutes.
Please be aware, we log all details and inputs of requests and make routine checks. If misuse occurs, we will permanently ban IP addresses, keys, and users from accessing the system without notice.
Automatic limits & blocks
Each user key can make up to 100 individual requests per minute, this should be more than enough for almost anything to be achievable. Multiple requests using invalid keys may result in a temporary IP ban - you must account for this by removing disabled or invalid keys upon error.
These limits may change without notice to ensure the Torn servers remain stable.
0 => 'Unknown error' : Unhandled error, should not occur.
1 => 'Key is empty' : Private key is empty in current request.
2 => 'Incorrect Key' : Private key is wrong/incorrect format.
3 => 'Wrong type' : Requesting an incorrect basic type.
4 => 'Wrong fields' : Requesting incorrect selection fields.
5 => 'Too many requests' : Current private key is banned for a small period of time because of too many requests (max 100 per minute).
6 => 'Incorrect ID' : Wrong ID value.
7 => 'Incorrect ID-entity relation' : A requested selection is private (For example, personal data of another user / faction).
8 => 'IP block' : Current IP is banned for a small period of time because of abuse.
9 => 'API disabled' : Api system is currently disabled.
10 => 'Key owner is in federal jail' : Current key can't be used because owner is in federal jail.
11 => 'Key change error': You can only change your API key once every 60 seconds.
12 => 'Key read error': Error reading key from Database.
Here there'll be short examples of code in several languages to see how you can use it.
r = requests.get("apiurl") # queries "apiurl" and returns response from Torn
data = r.json() # translates that response into a dict variable
print(data) # prints that variable
$jsonurl = "http://api.torn.com/user/[MyID]?selections=networth&key=[MyKey]"; $json = file_get_contents($jsonurl); //gets output of API $decodedString = json_decode($json, true); //parses API JSON output $nwtotal = $decodedString["networth"]; //Pulls networth out of JSON array echo "Stock Market: ".$nwtotal["stockmarket"]."
"; // Spits out networth from stocks echo "Networth Total: ".$nwtotal["total"]."
"; // Spits out total networth
Safe to use applications
Here there'll be a list of well known safe to use applications that require your API: