API documentation
Our website offers an API to registered users.
- You will need to use the POST method to create, update and delete your links automatically.
- You need an API key to use the API. Register if you haven't yet and you will automatically see your API key in your "Account" page.
- All link you create will be automatically associated with your account and can be managed as usual in the "Manage links" page.
Create a new link group or shorten one link
Example below shows you how to send request to our service to either combine several links into one, or shorten a single link.
<?php // ----- Required fields ----- // $multiAPI = 'your api key here'; // Your API key here $multiFormat = 'xml'; // Response format, can be set to either "json" or "xml" $multiType = 'group'; // Set to "group" to combine a group of links or to "single" for one link $multiLinks = array( // Store your links if $multiType is set to "group" 'http://www.google.com' => 'Google', 'http://www.yahoo.com' => '', ); $multiLink = 'http://www.google.com'; // Store your link if $multiType is set to "single" // ----- Optional fields for all link types ----- // $multiName = 'My group name'; // Name for your group or link $multiAlias = ''; // Alias for your group or link $multiPassword = ''; // Password for your group or link $multiToken = ''; // Token of existing group you're adding more links to // ----- Optional fields only for 'group' type ----- // $multiLinkback = '1'; // Show your linkback, "0" for no, "1" to show default, "2" for custom $multiLinkback_name = ''; // Linkback name (if the above is set to "2") $multiLinkback_url = ''; // Linkback URL (if the above is set to "2") // ----- No need to edit below this line ----- // $serviceURL = 'http://bitty.in/api/create'; $multiParams = 'api=' . $multiAPI . '&' . 'format=' . $multiFormat . '&' . 'type=' . $multiType . '&' . 'name=' . rawurlencode($multiName) . '&' . 'alias=' . rawurlencode($multiAlias) . '&' . 'password=' . rawurlencode($multiPassword) . '&' . 'linkback=' . $multiLinkback . '&' . 'linkback_name='. rawurlencode($multiLinkback_name) . '&' . 'linkback_url='. rawurlencode($multiLinkback_url); if ( $multiType == 'group' ) { if ( $multiToken ) { $multiParams .= "&token=$multiToken"; } foreach ( $multiLinks as $url => $name ) { $multiParams .= "&link[]=" . rawurlencode($name) . "\n" . rawurlencode($url); } } else { $multiParams .= "&link=" . rawurlencode($multiLink); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $serviceURL); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $multiParams); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); // ----- This is for display purposes ----- // echo '<pre>'.htmlspecialchars($data).'</pre>'; ?>
This will return the following response:
<?xml version="1.0" encoding="utf-8"?> <data> <token>0v</token> <short_list_url>http://bitty.in/l/0v</short_list_url> <short_toolbar_url>http://bitty.in/g/0v</short_toolbar_url> <links> <token>8x</token> <short_url>http://bitty.in/s/0v</short_url> <original_url>http://www.google.com</original_url> </links> <links> <token>8y</token> <short_url>http://bitty.in/s/0v</short_url> <original_url>http://www.yahoo.com</original_url> </links> </data>
If you would like to convert a single link, you will receive the following response:
<?xml version="1.0" encoding="utf-8"?> <data> <token>8A</token> <short_url>http://bitty.in/s/8A</short_url> <original_url>http://www.google.com</original_url> </data>
If something is wrong with your request, you will receive an error in this format:
<?xml version="1.0" encoding="utf-8"?> <data> <error>API key does not seem to be valid.</error> </data>
Update link group or link
Example below shows you how to send request to our service to update a group or a single link.
<?php // ----- Required fields ----- // $multiAPI = 'your api key here'; // Your API key here $multiFormat = 'xml'; // Response format, can be set to either "json" or "xml" $multiType = 'group'; // Set to "group" to update a group or to "single" for one link $multiToken = '1234'; // Token of a group or a link to update // ----- Fields you want to update, delete those you don't want to change ----- // $multiUpdate = array( 'name' => 'My group name', // Name for your group or link 'alias' => '', // Alias for your group or link 'password' => '', // Password for your group or link 'linkback' => '', // Show your linkback, "0" for no, "1" to show default, "2" for custom 'linkback_name' => '', // Linkback name (if the above is set to "2") 'linkback_url' => '', // Linkback URL (if the above is set to "2") ); // ----- No need to edit below this line ----- // $serviceURL = 'http://bitty.in/api/update'; $multiParams = 'api=' . $multiAPI . '&' . 'format=' . $multiFormat . '&' . 'type=' . $multiType . '&' . 'token=' . $multiToken; foreach ( $multiUpdate as $k => $v ) { $multiParams .= '&' . $k . '=' . rawurlencode($v); } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $serviceURL); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $multiParams); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); // ----- This is for display purposes ----- // echo '<pre>'.htmlspecialchars($data).'</pre>'; ?>
If successful, response will contain a token you have specified in your request along with your group's or link's URLs:
<?xml version="1.0" encoding="utf-8"?> <data> <token>0v</token> <short_list_url>http://bitty.in/l/0v</short_list_url> <short_toolbar_url>http://bitty.in/g/0v</short_toolbar_url> </data>
Delete link group or link
Example below shows you how to send request to our service to either remove a group of links, or remove a single link.
<?php // ----- Required fields ----- // $multiAPI = 'your api key here'; // Your API key here $multiFormat = 'xml'; // Response format, can be set to either "json" or "xml" $multiType = 'group'; // Set to "group" to delete a group of links or to "single" for one link $multiToken = '1234'; // Token of a group or a link to delete // ----- No need to edit below this line ----- // $serviceURL = 'http://bitty.in/api/delete'; $multiParams = 'api=' . $multiAPI . '&' . 'format=' . $multiFormat . '&' . 'type=' . $multiType . '&' . 'token=' . $multiToken; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $serviceURL); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $multiParams); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); // ----- This is for display purposes ----- // echo '<pre>'.htmlspecialchars($data).'</pre>'; ?>
If successful, response will contain a token you have specified in your request:
<?xml version="1.0" encoding="utf-8"?> <data> <token>1234</token> </data>
Get group or link details
Example below shows you how to send request to our service to get details of a group or link.
<?php // ----- Required fields ----- // $multiAPI = 'your api key here'; // Your API key here $multiFormat = 'xml'; // Response format, can be set to either "json" or "xml" $multiType = 'single'; // Set to "group" to get group's details or to "single" for link's details $multiToken = '1234'; // Token of a group or a link to get details for // ----- No need to edit below this line ----- // $serviceURL = 'http://bitty.in/api/info'; $multiParams = 'api=' . $multiAPI . '&' . 'format=' . $multiFormat . '&' . 'type=' . $multiType . '&' . 'token=' . $multiToken; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $serviceURL); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $multiParams); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); curl_close($ch); // ----- This is for display purposes ----- // echo '<pre>'.htmlspecialchars($data).'</pre>'; ?>
If successful, response will contain details about your group or link:
<?xml version="1.0" encoding="utf-8"?> <data> <token>nF</token> <alias>yahooo</alias> <name>Yahoo</name> <link>http://www.yahoo.com</link> <clicks>3215</clicks> </data>