A simple, authentication-free API for shortening URLs programmatically.
Shorten a URL via GET request. Ideal for simple browser-based implementations.
url
(required) - The URL to shorten (must start with http:// or https://)format
(optional) - Set to "simple" to receive just the shortened URL as plain textcustom
(optional) - Custom short code (4–32 alphanumeric characters, must be unique)GET https://lnk.ink/api/links/create?url=https://example.com
GET https://lnk.ink/api/links/create?url=https://example.com&format=simple
GET https://lnk.ink/api/links/create?url=https://example.com&custom=mycustom123&format=simple
Shorten a URL via POST request with JSON payload. Recommended for most applications.
{
"originalUrl": "https://example.com"
}
format
(optional) - Set to "simple" to receive just the shortened URL as plain textcustomCode
(optional) - Custom short code (4–32 alphanumeric characters)POST https://lnk.ink/api/links
Content-Type: application/json
{
"originalUrl": "https://example.com",
"format": "simple"
}
POST https://lnk.ink/api/links
Content-Type: application/json
{
"originalUrl": "https://example.com",
"customCode": "mycustom123"
}
Get statistics for a shortened URL.
code
(required) - The short code of the URLGET https://lnk.ink/api/links/SLnk/stats
Get the total number of shortened links in the system.
GET https://lnk.ink/api/links/stats/total
Successful requests return a JSON response with the following structure:
{
"originalUrl": "https://example.com",
"shortUrl": "https://lnk.ink/SLnk",
"shortCode": "SLnk",
"statsUrl": "https://lnk.ink/api/links/SLnk/stats",
"clicks": 0
}
originalUrl
- The original long URLshortUrl
- The complete shortened URLshortCode
- The unique identifier for your shortened URLstatsUrl
- URL to view statistics for this shortened linkclicks
- Number of times the link has been clickedWhen format=simple
is specified, the response is just the shortened URL as plain text:
https://lnk.ink/SLnk
Statistics endpoint returns detailed information about a shortened URL:
{
"originalUrl": "https://example.com",
"shortUrl": "https://lnk.ink/SLnk",
"clicks": 42,
"createdAt": "2023-01-01T00:00:00.000Z",
"lastAccessed": "2023-06-15T12:34:56.789Z"
}
Total links endpoint returns a simple count:
{
"total": 12345
}
Error responses follow this format:
{
"error": "Error message",
"details": "Additional details in development mode"
}
400 Bad Request
- Missing or invalid URL (must start with http:// or https://)404 Not Found
- Short code not found (for stats endpoint)500 Internal Server Error
- Server error while processing requestcurl -X POST https://lnk.ink/api/links \
-H "Content-Type: application/json" \
-d '{"originalUrl":"https://example.com", "customCode": "mycustom123"}'
curl https://lnk.ink/api/links/SLnk/stats
const axios = require('axios');
// Shorten URL
async function shortenUrl(url) {
try {
const response = await axios.post('https://lnk.ink/api/links', {
originalUrl: url
});
console.log('Shortened URL:', response.data.shortUrl);
return response.data;
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
}
// Get stats
async function getStats(code) {
try {
const response = await axios.get(`https://lnk.ink/api/links/${code}/stats`);
console.log('Stats:', response.data);
return response.data;
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
}
// Usage
shortenUrl('https://example.com');
getStats('SLnk');
$url];
$options = [
'http' => [
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents('https://lnk.ink/api/links', false, $context);
return json_decode($result, true);
}
// Get stats
function getStats($code) {
$result = file_get_contents("https://lnk.ink/api/links/{$code}/stats");
return json_decode($result, true);
}
// Usage
$shortened = shortenUrl('https://example.com');
echo 'Shortened URL: ' . $shortened['shortUrl'];
$stats = getStats('SLnk');
echo 'Clicks: ' . $stats['clicks'];
?>
import requests
# Shorten URL
def shorten_url(url):
try:
response = requests.post(
'https://lnk.ink/api/links',
json={'originalUrl': url}
)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
return None
# Get stats
def get_stats(code):
try:
response = requests.get(f'https://lnk.ink/api/links/{code}/stats')
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
return None
# Usage
shortened = shorten_url('https://example.com')
if shortened:
print(f"Shortened URL: {shortened['shortUrl']}")
stats = get_stats('SLnk')
if stats:
print(f"Clicks: {stats['clicks']}")
The API only accepts valid URLs that start with either http://
or https://
. All other URLs will be rejected with a 400 Bad Request error.
Redirects are cached for 1 minute to improve performance. Stats may not reflect clicks that occurred within the last minute.