Campaign Tracking with API integration

Although’s URL shortening service is frequently used in conjunction with Twitter, its use is not limited to that. can be used to track any social network or e-mail marketing campaign, as it tracks information about the number of clicks and your audience. They also offer an API, so you can connect it with your application and automate the analysis process. Continue reading to learn how to integrate the API with your application.

API Overview API uses two types of authentication. If you just want to shorten links on behalf of a single user or website, you can call the API shorten method using the generic OAuth token. On the other hand, if you are working with multiple users or want to access user-level data ( history, analytics, etc.), you will need to register an app and use the usual OAuth authentication flow.

API responses are in JSON format by default. However, XML format is also available. When a request is successful, the HTTP status code will be 200. HTTP status codes that indicate errors are:

  • 403 — Rate limited
  • 503 — Service temporary unavailable
  • 404 — Page not found
  • 400 — Other invalid requests

A sample response would look like this:

// Successful response{ "status_code": 200, "status_txt": "OK", "data" : ... }// Unsuccessful response{ "status_code": 403, "status_txt": "RATE_LIMIT_EXCEEDED", "data" : null }

The API has three endpoint URLs:

To make the integration easier, there are many API libraries for a variety of programming languages, that can be downloaded from here.

Link Shortening

As mentioned above, this is the simplest (but also very common) API use-case. It does not require the usual OAuth authentication flow, but just a generic OAuth access token, which can be created here.

Once you have done that, you will only have to request the following URL using the HTTP GET method:

Note that the is the API URL, v3/shorten is the method that we are calling, and the parameters are passed as GET parameters. Also, the URL you are shortening should be encoded. A sample response would look like this:

{                "status_code": 200,                "status_txt": "OK",                "data": {                                 "long_url": "",                                 "url": "",                                 "hash": "1GBL67S",                                "global_hash": "LmvF",                                 "new_hash": 1                    } }

OAuth Authentication

OAuth authentication is a bit more difficult. It is used when you want to work with multiple users or access user-level data. After registering your app, the first step is to redirect a user to the following URL:

Client ID is obtained during the app registration, while the redirect URI is the location of the PHP script that will exchange a request token for an access token. So, once the user is redirected to the URL above, he will have to confirm that he allows your app to access his data. Once that is done, he will be redirected to the redirect URI. would send the request token (code) to this URI and then the request token will be exchanged for an access token. If everything goes fine, you can call API methods using the obtained access token.

The redirect URI PHP script would contain the code similar to this:

$value) { $params_string .= $key.'='.$value.'&'; }  		rtrim($params_string,'&');  	try {		$ch = curl_init();		curl_setopt($ch,CURLOPT_URL, $uri);		curl_setopt($ch,CURLOPT_POST, count($params));		curl_setopt($ch,CURLOPT_POSTFIELDS, $params_string);		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);	    	$output = curl_exec($ch);  	} catch (Exception $e) {  	}	// Returns a URL encoded string in the format of "access_token=%s&login=%s&apiKey=%s"		// parse_str() creates variables $access_token and $login	parse_str($output);	// The access token for specified user	echo $access_token;	// The end-user's Bitly username	echo $login;	// Call API methods here	// Store access token in session for later use ?> 

Next Steps

It is good practice to save the access token in a session, so you don’t have to do the exchange each time you want to make an API call.

Also, read about other available API methods here. Calling them is the same as calling the v3/shorten method.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS