Open API | Powered By | Contact

API for developers

If you need short URL service integration with your site, this service provides API which works with JSON.

JSON Format:

{
  "longurl":"loooooong",
  "shorturl":"short"
}

Simpliest method is $.ajax() or $.getJSON() : all you need is to send query string with URL encoded like:


http://udanax.org/shorturl.jsp?mode=api&longurl=http%3A%2F%2Fblog.udanax.org%2F

AJAX Example:

<script src="jquery-latest.js" type="text/javascript"></script>
<script type="text/javascript">
  var longUrl = escape("http://lyricsbird.net/");

  var shortener = "http://udanax.org/";
  $.ajax({
    type: 'GET',
    url: shortener + "shorturl.jsp?mode=api&longurl=" + longUrl +"&jsoncallback=?",
    dataType: 'json',
    timeout: 6000,
    success: function(data, status) {
      alert(shortener + data.shorturl);
    },
    error: function (request, status, error) {
      alert(-1);
    }
  });
</script>

PHP Example:

<?php
  function getShortURL($longUrl) {
    $url = "http://udanax.org/shorturl.jsp?mode=api&longurl=";
    $url .= urlencode($longUrl);
    $data = file_get_contents($url);
    $json = json_decode($data, true);
    return "http://udanax.org/".$json['shorturl'];
  }

  echo getShortUrl("http://www.google.com/");
?>

© 2010 udanax.org