NAV
javascript php bash

Info

Welcome to the API docs for T.ly

Download the Postman Collection

Links

Shorten

Example request:

const url = new URL('https://t.ly/api/v1/link/shorten');

let headers = {
    'Content-Type': 'application/json',
    Accept: 'application/json'
};

let body = {
    long_url: 'http://example.com/',
    api_token: 'xxxxxxxxx'
};

fetch(url, {
    method: 'POST',
    headers: headers,
    body: body
})
    .then(response => response.json())
    .then(json => console.log(json));

$client = new \GuzzleHttp\Client();
$response = $client->post("https://t.ly/api/v1/link/shorten", [
    'headers' => [
            "Content-Type" => "application/json",
        ],
    'json' => [
            "long_url" => "http://example.com/",
            "api_token" => "xxxxxxxxx",
        ],
]);
$body = $response->getBody();
print_r(json_decode((string) $body));
curl -X POST "https://t.ly/api/v1/link/shorten" \
    -H "Content-Type: application/json" \
    -d '{"long_url":"http:\/\/example.com\/","api_token":"xxxxxxxxx"}'

Example response (200):

{
    "short_url": "https://t.ly/40a"
}

HTTP Request

POST api/v1/link/shorten

Body Parameters

Parameter Type Status Description
long_url url required The long url to be shortened.
api_token string required API key.

Expand

Example request:

const url = new URL('https://t.ly/api/v1/link/expand');

let params = {
    short_url: 'https://t.ly/OYXL',
    api_token: 'xxxxxxxxx'
};
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));

let headers = {
    Accept: 'application/json',
    'Content-Type': 'application/json'
};

fetch(url, {
    method: 'GET',
    headers: headers
})
    .then(response => response.json())
    .then(json => console.log(json));

$client = new \GuzzleHttp\Client();
$response = $client->get("https://t.ly/api/v1/link/expand", [
    'query' => [
            "short_url" => "https://t.ly/OYXL",
            "api_token" => "xxxxxxxxx",
        ],
]);
$body = $response->getBody();
print_r(json_decode((string) $body));
curl -X GET -G "https://t.ly/api/v1/link/expand?short_url=https%3A%2F%2Ft.ly%2FOYXL&api_token=xxxxxxxxx"

Example response (200):

{
    "long_url": "http: //example.com/"
}

HTTP Request

GET api/v1/link/expand

Query Parameters

Parameter Status Description
short_url required Short url to be expanded.
api_token required API key.

Stats

Example request:

const url = new URL('https://t.ly/api/v1/link/stats');

let params = {
    short_url: 'https://t.ly/OYXL',
    api_token: 'xxxxxxxxx'
};
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));

let headers = {
    Accept: 'application/json',
    'Content-Type': 'application/json'
};

fetch(url, {
    method: 'GET',
    headers: headers
})
    .then(response => response.json())
    .then(json => console.log(json));

$client = new \GuzzleHttp\Client();
$response = $client->get("https://t.ly/api/v1/link/stats", [
    'query' => [
            "short_url" => "https://t.ly/OYXL",
            "api_token" => "xxxxxxxxx",
        ],
]);
$body = $response->getBody();
print_r(json_decode((string) $body));
curl -X GET -G "https://t.ly/api/v1/link/stats?short_url=https%3A%2F%2Ft.ly%2FOYXL&api_token=xxxxxxxxx"

Example response (200):

{
    "clicks": 21,
    "browsers": [
        {
            "browser": "Chrome",
            "total": 14
        },
        {
            "browser": "Firefox",
            "total": 2
        }
    ],
    "referrers": [
        {
            "referrer": "Unknown",
            "total": 13
        }
    ],
    "platforms": [
        {
            "platform": "Mac",
            "total": 8
        },
        {
            "platform": "Windows",
            "total": 5
        }
    ],
    "data": {
        "long_url": "https://example.com/",
        "short_url": "https://t.ly/OYXL",
        "created_at": "2019-08-03 14:47:40"
    }
}

HTTP Request

GET api/v1/link/stats

Query Parameters

Parameter Status Description
short_url required Get stats for short url.
api_token required API key.

Update

Example request:

const url = new URL('https://t.ly/api/v1/link');

let headers = {
    'Content-Type': 'application/json',
    Accept: 'application/json'
};

let body = {
    short_url: 'https://t.ly/OYXL',
    long_url: 'https://t.ly/OYXL',
    expire_at_time: '2018-10-06 20:14:45',
    expire_at_views: '9',
    api_token: 'xxxxxxxxx'
};

fetch(url, {
    method: 'PUT',
    headers: headers,
    body: body
})
    .then(response => response.json())
    .then(json => console.log(json));

$client = new \GuzzleHttp\Client();
$response = $client->put("https://t.ly/api/v1/link", [
    'headers' => [
            "Content-Type" => "application/json",
        ],
    'json' => [
            "short_url" => "https://t.ly/OYXL",
            "long_url" => "https://t.ly/OYXL",
            "expire_at_time" => "2018-10-06 20:14:45",
            "expire_at_views" => "9",
            "api_token" => "xxxxxxxxx",
        ],
]);
$body = $response->getBody();
print_r(json_decode((string) $body));
curl -X PUT "https://t.ly/api/v1/link" \
    -H "Content-Type: application/json" \
    -d '{"short_url":"https:\/\/t.ly\/OYXL","long_url":"https:\/\/t.ly\/OYXL","expire_at_time":"2018-10-06 20:14:45","expire_at_views":"9","api_token":"xxxxxxxxx"}'

Example response (204):

[]

HTTP Request

PUT api/v1/link

Body Parameters

Parameter Type Status Description
short_url url required The short url.
long_url url optional The long url to be updated.
expire_at_time TimeStamp optional Time url will expire.
expire_at_views Integer optional Number of days the short url will be valid.
api_token string required API key.

Delete

Example request:

const url = new URL('https://t.ly/api/v1/link');

let params = {
    short_url: 'https://t.ly/OYXL',
    api_token: 'xxxxxxxxx'
};
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));

let headers = {
    Accept: 'application/json',
    'Content-Type': 'application/json'
};

fetch(url, {
    method: 'DELETE',
    headers: headers
})
    .then(response => response.json())
    .then(json => console.log(json));

$client = new \GuzzleHttp\Client();
$response = $client->delete("https://t.ly/api/v1/link", [
    'query' => [
            "short_url" => "https://t.ly/OYXL",
            "api_token" => "xxxxxxxxx",
        ],
]);
$body = $response->getBody();
print_r(json_decode((string) $body));
curl -X DELETE "https://t.ly/api/v1/link?short_url=https%3A%2F%2Ft.ly%2FOYXL&api_token=xxxxxxxxx"

Example response (202):

[]

HTTP Request

DELETE api/v1/link

Query Parameters

Parameter Status Description
short_url required Get stats for short url.
api_token required API key.