API Usage in PHP

Ushort.io Ushort.io / Support Last updated on Updated  Aug 03, 2020

An API key is required for requests to be processed by the system. Once a user registers, an API key is automatically generated for this user. The API key must be sent with each request via the key parameter (see full example below). If the API key is not sent or is expired, there will be an error. Please make sure to keep your API key secret to prevent abuse.


Your first integration

The example below shows you how to shorten a URL without any other parameters. You need to get your API key from the settings page of the user control panel


include("Shortener.php");


$shortener = new kbrmedia\Shortener();


// Set the URL & API key

$shortener->setURL("http://ushort.io/api");

$shortener->setKey("APIKEY");


// Simple call

echo $shortener->shorten("https://ushort.io");

Get short URL directly

To get the Short URL directly without having to deal with JSON you can chain the toText() method as below


// Get short URL directly

echo $shortener->toText()->shorten("https://ushort.io");

Advanced Call

To customize the URL, you can use the below to set a custom alias and the format - which in this case is in text


// Custom Alias

$shortener->setCustom("ushort");


// Set Type

$shortener->setType("frame");


// Set Password

$shortener->setPassword("123456");


// Format: text or json

$shortener->setFormat("text");


echo $shortener->shorten("https://ushort.io");

Get detail or data for a short URL

This sample allows you to unshorten a URL and some data


var_dump($shortener->details("ushort"));

Get all of your URLs on your account

This sample allows you to get all of your URLs in your account. It has two parameters: sort [date or click] and limit (number of urls)


var_dump($shortener->urls());