Usage Examples


cURL

Shorten URL using "application/json" content type:

curl -X POST "https://rpl.ltd/tiny/api/3/urls" \
-H "X-Tinycc-User: john_d" \
-H "X-Tinycc-Key: 2cd573c2-33a5-41cc-94ce-6030e8a026b1" \
-H "Content-Type: application/json" \
-d '{"urls":[{"long_url":"https://example.com/your-long-url","custom_hash":"example","note":"My first link!"}]}'

Shorten URL using "application/x-www-form-urlencoded" content type:

curl -X POST "https://rpl.ltd/tiny/api/3/urls" \
-H "X-Tinycc-User: john_d" \
-H "X-Tinycc-Key: 2cd573c2-33a5-41cc-94ce-6030e8a026b1" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "urls[0][long_url]=https://example.com/your-long-url&urls[0][custom_hash]=example&urls[0][note]=My%20first%20link!"

PHP

Shorten URL using stream functions:

$long_url = 'https://example.com/your-long-url';
$custom_hash = "example";
$note = 'My first link!';

$api_user = 'john_d';
$api_key = '2cd573c2-33a5-41cc-94ce-6030e8a026b1';
$api_endpoint = 'https://rpl.ltd/tiny/api/3/urls';

$payload = json_encode([
'urls'=>[
[
'long_url'=>$long_url,
'custom_hash'=>$custom_hash,
'note'=>$note
]
]
]);

$context = stream_context_create([
'http'=>[
'method'=>'POST',
'header'=>implode("\r\n",[
'Content-Type: application/json',
'Content-Size: '.strlen($payload),
'X-Tinycc-User: '.$api_user,
'X-Tinycc-Key: '.$api_key,
]),
'content'=>$payload,
'ignore_errors'=>'1'
]
]);

$stream = @fopen($api_endpoint, 'r', false, $context);

if(!$stream){
die('Connection error!'.PHP_EOL);
}

$response = @json_decode(stream_get_contents($stream), true);
fclose($stream);

if(empty($response['error']['code'])){
if(empty($response['urls'][0]['error']['code'])){
print_r($response['urls'][0]);
}else{
print 'Error:'.PHP_EOL;
print_r($response['urls'][0]['error']);
}
}else{
print 'Error:'.PHP_EOL;
print_r($response['error']);
}

print PHP_EOL;

JavaScript

Shorten URL using fetch() method:

async function shorten()
{
const api_url = "https://rpl.ltd/tiny/api/3/urls",
api_user = "john_d",
api_key = "2cd573c2-33a5-41cc-94ce-6030e8a026b1",
data = {
urls:[
{
long_url: 'https://example.com/your-long-url',
custom_hash: 'example',
note: 'My first link!'
}
]
};

return fetch(api_url, {
method: "POST",
body: JSON.stringify(data),
mode: 'cors',
headers: {
"Content-Type": "application/json",
"X-Tinycc-User": api_user,
"X-Tinycc-Key": api_key
}
});
};

shorten()
.then((response) => {
if (response.ok) {
// Get JSON value from the response body
return response.json();
}
throw new Error(`HTTP error! Status: ${response.status}`);
})
.then((result) => console.log(result))
.catch((error) => console.error(error));