Lnk.ink API Documentation

A simple, authentication-free API for shortening URLs programmatically.

API Endpoints

GET /api/links/create

Shorten a URL via GET request. Ideal for simple browser-based implementations.

Parameters

  • 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 text
  • custom (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

POST /api/links

Shorten a URL via POST request with JSON payload. Recommended for most applications.

Request Body

{
  "originalUrl": "https://example.com"
}

Query Parameters

  • format (optional) - Set to "simple" to receive just the shortened URL as plain text
  • customCode (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 /api/links/{code}/stats

Get statistics for a shortened URL.

Parameters

  • code (required) - The short code of the URL
GET https://lnk.ink/api/links/SLnk/stats

GET /api/links/stats/total

Get the total number of shortened links in the system.

GET https://lnk.ink/api/links/stats/total

Response Formats

Standard JSON Response

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
}

Fields

  • originalUrl - The original long URL
  • shortUrl - The complete shortened URL
  • shortCode - The unique identifier for your shortened URL
  • statsUrl - URL to view statistics for this shortened link
  • clicks - Number of times the link has been clicked

Simple Text Response

When format=simple is specified, the response is just the shortened URL as plain text:

https://lnk.ink/SLnk

Stats Response

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 Response

Total links endpoint returns a simple count:

{
  "total": 12345
}

Error Responses

Error responses follow this format:

{
  "error": "Error message",
  "details": "Additional details in development mode"
}

Common Errors

  • 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 request

Code Examples

cURL
Node.js
PHP
Python

Create Short Link

curl -X POST https://lnk.ink/api/links \
  -H "Content-Type: application/json" \
  -d '{"originalUrl":"https://example.com", "customCode": "mycustom123"}'

Get Stats

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']}")

Additional Information

URL Validation

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.

Caching

Redirects are cached for 1 minute to improve performance. Stats may not reflect clicks that occurred within the last minute.

Back to lnk.ink