API Documentation

Integrate Linkrr into your applications with our RESTful API.

Introduction

The Linkrr API allows you to programmatically create short links, manage your links, and retrieve detailed analytics data. Our API follows REST principles and returns JSON responses.

Base URL:

https://t.wpsanjeet.com/api

Response Format:

JSON (application/json)

Need help? If you encounter any issues, check our Troubleshooting section or contact support.

Quick Start

Test if your API key works with this simple request:

curl https://t.wpsanjeet.com/api/?endpoint=links \
  -H "Authorization: Bearer YOUR_API_KEY"

Expected successful response:

{
  "success": true,
  "data": [
    {
      "id": 1,
      "short_code": "abc123",
      "short_url": "https://t.wpsanjeet.com/abc123",
      "long_url": "https://example.com",
      "title": "My Link",
      "clicks": 42,
      "status": "active",
      "created_at": "2024-01-15 10:30:00"
    }
  ]
}

Endpoints Overview

Endpoint Method Description
/api/?endpoint=shorten POST Create a new short link
/api/?endpoint=links GET List all your links
/api/?endpoint=links&id={id} DELETE Delete a specific link
/api/?endpoint=analytics GET Get analytics data
/api/?endpoint=bio-pages GET List bio pages

Authentication

All API requests require authentication. You can provide your API key in three ways:

Method 1: Authorization Header (Recommended)

Authorization: Bearer YOUR_API_KEY

Method 2: X-API-Key Header

X-API-Key: YOUR_API_KEY

Method 3: Query Parameter (Less Secure)

https://t.wpsanjeet.com/api/?endpoint=links&api_key=YOUR_API_KEY

Important: API keys are available for Pro and Agency plans only. Free plan users cannot access the API.

Get your API key from your dashboard. Keep your API key secure and never expose it in client-side code.

POST Shorten URL

Create a new short link from a long URL. You can optionally specify a custom alias and title.

POST /api/?endpoint=shorten

Request Body Parameters

Parameter Type Required Description
url string Yes The long URL to shorten (must be valid URL)
alias string No Custom short code (3-50 chars, alphanumeric + hyphen/underscore)
title string No Optional title for the link

Example Request

curl -X POST https://t.wpsanjeet.com/api/?endpoint=shorten \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/my-long-url",
    "alias": "mylink",
    "title": "My Custom Link"
  }'

Example Response (Success)

{
  "success": true,
  "data": {
    "short_url": "https://t.wpsanjeet.com/mylink",
    "short_code": "mylink",
    "long_url": "https://example.com/my-long-url",
    "qr_code_url": "https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https%3A%2F%2Ft.wpsanjeet.com%2Fmylink",
    "created_at": "2024-01-15 10:30:00"
  }
}

Example Response (Error - Alias Taken)

{
  "error": "Custom alias already taken"
}

GET Analytics

Retrieve detailed click analytics for your links. Get account-wide summary or specific link analytics.

GET /api/?endpoint=analytics&link_id={id}&days={days}

Query Parameters

Parameter Type Required Description
link_id integer No Specific link ID. Omit for account-wide summary.
days integer No Number of days to analyze (1-90, default 30)

Example Requests

Account-wide summary:

curl "https://t.wpsanjeet.com/api/?endpoint=analytics&days=30" \
  -H "Authorization: Bearer YOUR_API_KEY"

Specific link analytics:

curl "https://t.wpsanjeet.com/api/?endpoint=analytics&link_id=123&days=7" \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response (Account Summary)

{
  "success": true,
  "data": {
    "summary": {
      "total_clicks": 1500,
      "unique_clicks": 1200,
      "total_links": 25
    },
    "devices": [
      { "device_type": "mobile", "count": 900 },
      { "device_type": "desktop", "count": 500 },
      { "device_type": "tablet", "count": 100 }
    ],
    "countries": [
      { "country": "United States", "count": 800 },
      { "country": "United Kingdom", "count": 300 },
      { "country": "India", "count": 200 }
    ]
  }
}

GET Bio Pages

List all your bio link pages with their details.

GET /api/?endpoint=bio-pages

Example Request

curl https://t.wpsanjeet.com/api/?endpoint=bio-pages \
  -H "Authorization: Bearer YOUR_API_KEY"

Example Response

{
  "success": true,
  "data": [
    {
      "id": 1,
      "username": "john",
      "page_title": "John's Links",
      "bio_text": "Welcome to my bio page",
      "views": 500,
      "status": "active",
      "created_at": "2024-01-10 14:20:00",
      "url": "https://t.wpsanjeet.com/john"
    }
  ]
}

Code Examples

Ready-to-use code snippets in popular programming languages.

PHP

<?php
$apiKey = 'YOUR_API_KEY';
$url = 'https://example.com/my-long-url';

// Create short link
$ch = curl_init('https://t.wpsanjeet.com/api/?endpoint=shorten');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['url' => $url]));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiKey,
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);
if ($data['success']) {
    echo "Short URL: " . $data['data']['short_url'];
}
?>

JavaScript (Node.js / Fetch)

const API_KEY = 'YOUR_API_KEY';

// Create short link
async function createShortLink(url) {
  const response = await fetch('https://t.wpsanjeet.com/api/?endpoint=shorten', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${API_KEY}`,
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      url: url,
      alias: 'custom-alias'  // optional
    })
  });
  
  const data = await response.json();
  if (data.success) {
    console.log('Short URL:', data.data.short_url);
    return data.data;
  } else {
    console.error('Error:', data.error);
  }
}

// List all links
async function listLinks() {
  const response = await fetch('https://t.wpsanjeet.com/api/?endpoint=links', {
    headers: { 'Authorization': `Bearer ${API_KEY}` }
  });
  const data = await response.json();
  return data.data;
}

Python

import requests

API_KEY = 'YOUR_API_KEY'
BASE_URL = 'https://t.wpsanjeet.com/api'
headers = {'Authorization': f'Bearer {API_KEY}'}

# Create short link
def create_short_link(url, alias=None):
    data = {'url': url}
    if alias:
        data['alias'] = alias
    
    response = requests.post(
        f'{BASE_URL}/?endpoint=shorten',
        headers={**headers, 'Content-Type': 'application/json'},
        json=data
    )
    return response.json()

# List all links
def list_links():
    response = requests.get(
        f'{BASE_URL}/?endpoint=links',
        headers=headers
    )
    return response.json()

# Get analytics
def get_analytics(days=30):
    response = requests.get(
        f'{BASE_URL}/?endpoint=analytics&days={days}',
        headers=headers
    )
    return response.json()

# Example usage
result = create_short_link('https://example.com', 'mylink')
print(f"Short URL: {result['data']['short_url']}")

PowerShell

$API_KEY = "YOUR_API_KEY"

# Create short link
$body = @{
    url = "https://example.com"
    alias = "mylink"
} | ConvertTo-Json

Invoke-RestMethod `
  -Method Post `
  -Uri "https://t.wpsanjeet.com/api/?endpoint=shorten" `
  -Headers @{
    "Authorization" = "Bearer $API_KEY"
    "Content-Type" = "application/json"
  } `
  -Body $body

# List links
Invoke-RestMethod `
  -Uri "https://t.wpsanjeet.com/api/?endpoint=links" `
  -Headers @{ "Authorization" = "Bearer $API_KEY" }

# Delete link (using GET workaround if DELETE blocked)
Invoke-RestMethod `
  -Uri "https://t.wpsanjeet.com/api/?endpoint=links&id=123&action=delete" `
  -Headers @{ "Authorization" = "Bearer $API_KEY" }

Troubleshooting

401 - Invalid or missing API key

Your API key is invalid, expired, or not provided correctly.

  • Verify your API key is copied correctly from the dashboard
  • Ensure the key hasn't been revoked
  • Check your plan supports API access (Pro or Agency required)
  • Verify the Authorization header format: Bearer YOUR_KEY

403 - Link limit reached

You've reached the maximum number of links for your plan.

  • Delete unused links to free up space
  • Upgrade to a higher plan for more links
  • Unlimited plans (-1) should not see this error

405 - Method Not Allowed

Your server blocks DELETE requests. Use the workaround:

GET https://t.wpsanjeet.com/api/?endpoint=links&id=123&action=delete

409 - Custom alias already taken

The alias you requested is already in use. Try a different alias or leave blank for auto-generated code.

API not working at all?

  • Test the base URL: https://t.wpsanjeet.com/api/ should return JSON
  • Check if your server has mod_rewrite enabled
  • Verify the api/ folder exists and is readable
  • Check PHP error logs for server-side issues

Rate Limits

To ensure fair usage, API requests are rate limited based on your plan:

Plan Rate Limit API Access
Free N/A Not Available
Pro 1,000 requests per hour Available
Agency 10,000 requests per hour Available

If you exceed your rate limit, the API will return 429 Too Many Requests. Wait for the limit to reset or upgrade your plan.

Error Codes

Code Name Description
200OKRequest successful
400Bad RequestInvalid parameters (e.g., invalid URL format)
401UnauthorizedInvalid or missing API key
403ForbiddenPlan limit reached (links, requests, etc.)
404Not FoundResource doesn't exist (e.g., link ID not found)
405Method Not AllowedHTTP method not supported for endpoint
409ConflictCustom alias already taken
429Too Many RequestsRate limit exceeded
500Server ErrorInternal server error (contact support)