Difference between revisions of "API:Core"

From TheHostingTool Wiki
Jump to navigationJump to search
Line 11: Line 11:
  
 
==Calling a Function==
 
==Calling a Function==
===Method One===
+
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.
===Method Two===
+
 
 +
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:
 +
<pre>http://mydomain.tld/THT_DIR/xml-api/function/params/auth_hash</pre>
 +
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:
 +
<pre>$hash = hash('sha512', sha1('function_name|parameters') . sha1($my_tht_api_key));</pre>
 +
<br />
 +
===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:
 +
<pre>$hash = hash('sha512', sha1('listaccts') . sha1($my_tht_api_key));</pre>
 +
And the request URL would be:
 +
<pre>http://mydomain.tld/THT_DIR/xml-api/function/auth_hash</pre>

Revision as of 01:47, 15 February 2010

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/function/auth_hash