Associating urls created with API to your account

Recently while working on adding the feature to enter your own API key to my Easy Retweet WordPress Plugin, I found out that by default all short urls created using API (both REST and JavaScript API’s) are not associated with your account.

Upon further researching I found that there is an undocumented way of associating the urls created with your account. The undocumented way is to add an additional parameter called history with value 1 to the API URL.

Using the history parameter in’s REST API

So for REST API, you have to use the following url.

If you are using PHP, then code would be

function get_bitly_shorturl($longurl) {
	$url = "" . "&longurl=$longurl";

	//using curl
	$curlObject = curl_init();

	$result_json = curl_exec($curlObject);

	//decode JSON. Assumes that it is PHP5
	$result = json_decode($result_json);

	return $result['results'][shortUrl];

If you are going to use it in WordPress, then you can use the inbuilt WP_Http class instead of curl as suggested by Ozh. The following code shows you how it can be done in WordPress

function get_bitly_shorturl($longurl) {
	$url = "" . "&longurl=$longurl";

	//using WP_Http present in WordPress
	$request = new WP_Http;
	$result_json = $request->request($url);

	$result = json_decode($result_json);

	return $result['results'][shortUrl];

Using the history parameter in’s JavaScript API

If you are using’s JavaScript API, then it is not as straight forward as the REST API. Instead of using the provided shorten method, you have to use the low level call method.

The following code shows you how you can do it in JavaScript API.'shorten', {'longUrl':'', 'history':'1'}, 'BitlyCB.shortenResponse');

I am not sure why is not associating the created shorturls automatically with your account, when you provide the API Key, it is the expected default behavior. Or at least they could have documented about this history variable in their API. I guess only someone from can answer this. 🙂

Related posts

Tags: , ,

4 Comments so far

Follow up comments through RSS Feed | Post a comment

2 Tweetbacks so far

2 Trackbacks/Pingbacks so far

Leave a Reply

Your email address will not be published. Required fields are marked *