Difference between revisions of "API:Core"

From TheHostingTool Wiki
Jump to: navigation, search
(If not using a parameter)
m (Added "warning")
Line 1: Line 1:
 +
The API is currently under development. Changes are to be made! And big ones! So this won't be accurate till the API is finalized. THT 1.3?
 +
 
==Setting Up an Authentication Key==
 
==Setting Up an Authentication Key==
 
Use the Gallery for information:
 
Use the Gallery for information:

Revision as of 11:50, 15 February 2010

The API is currently under development. Changes are to be made! And big ones! So this won't be accurate till the API is finalized. THT 1.3?

Setting Up an Authentication Key

Use the Gallery for information:

Calling a Function

The API uses a REQUEST system -- this means you can submit your variables via POST or GET. Requests are made to xml-api/index.php. The xml-api directory will be found in the THT directory. For these examples, we will be using PHP as our language for coding a script to get a list of accounts. For simplicity, we will be using a GET request.

You will need to create a hash of the function.

If using a parameter

To call a function with a parameter using the XML-API, you would make a request to:

http://mydomain.tld/THT_DIR/xml-api/function/params/auth_hash

To create your auth hash, you need to generate a sha512 hash and two sha1 hashes. The two sha1 hashes are generated, joined together, and are then used to create a sha512 hash. Your hashing code should look like this:

$hash = hash('sha512', sha1('function_name|parameters') . sha1($my_tht_api_key));

If not using a parameter

So now let's get a list of users. We'll assume you already have your API key. Now, the hashing and access method change. To generate a hash:

$hash = hash('sha512', sha1('listaccts') . sha1($my_tht_api_key));

And the request URL would be:

http://mydomain.tld/THT_DIR/xml-api/listaccts/auth_hash

Now, the function to list accounts would be API:listaccts, which we'll get into on that function's wiki page. There are no parameters. We'll make a cURL GET request to process a list of users, which will be returned in XML.

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://mydomain.tld/THT_DIR/xml-api/listaccts/auth_hash');
$val = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($val);
unset($val);
echo $xml->acct[0]->domain[0];
?>

If you have at least one client, this will output the domain of the first account in the array.