API Info

Simply have your application access a URL similar to the following, via an HTTP GET request: http://to.ly/api.php?longurl=http://www.example.com

cURL Command Line Example

curl -d "longurl={YOUR LONG URL HERE}" https://to.ly/api.php

Returns the shortened link on a single line. Replace {YOUR LINK HERE} with your link... please omit curly brackets!

JSON/jQuery Example

function CompressURL(url,success)

var link = 'https://to.ly/api.php?json=1&longurl=' + encodeURIComponent(url) + '&callback=?';

$.getJSON(link, function(data){
success && success(data.shorturl);


CompressURL("https://www.twitter.com/jonasl", function(shorturl) {



PHP Source Code Example

This example requires cURL (ubuntu/linux package name is php5-curl)

function CompressURL($url) {

  $ch = curl_init();

  curl_setopt($ch, CURLOPT_URL, "https://to.ly/api.php?longurl=".urlencode($url));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch, CURLOPT_HEADER, 0);

  $shorturl = curl_exec ($ch);
  curl_close ($ch);

  return $shorturl;


echo CompressURL("https://twitter.com"); // Test

Python Source Code Example

import urllib

def CompressURL(url):
    """Compress the URL using to.ly"""
    apiurl = "https://to.ly/api.php?longurl="
    quoted = urllib.quote_plus(url)
    shorturl = urllib.urlopen(apiurl + quoted).read()
    return shorturl

print CompressURL("https://www.twitter.com")
© Triop AB