Blog / API Developer Guide

Urlyte API Developer Guide: Integrate URL Shortening Into Your Apps

Published on January 7, 202512 min read
Urlyte Logo

Urlyte's powerful API enables developers to integrate professional URL shortening, analytics, and link management directly into their applications. This comprehensive guide covers everything you need to get started.

Getting Started with Urlyte API

The Urlyte API is a RESTful service that provides programmatic access to all core platform features. Whether you're building a social media management tool, marketing automation platform, or custom business application, our API makes integration straightforward and reliable.

API Overview

  • Base URL: https://api.urlyte.io/v1
  • Authentication: API key-based
  • Format: JSON request/response
  • Rate Limits: 1000 requests/hour (free), unlimited (premium)
  • HTTPS: Required for all requests

Authentication

All API requests require authentication using your API key. Include your key in the request header:

Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

🔑 Getting Your API Key

Log into your Urlyte dashboard, navigate to Settings → API, and generate your API key. Keep it secure and never expose it in client-side code.

Core API Endpoints

1. Create Short Link

The most commonly used endpoint for creating shortened URLs:

POST /links

{
  "url": "https://example.com/very-long-url",
  "custom_alias": "my-link",
  "title": "My Custom Link",
  "description": "Link description for analytics",
  "tags": ["marketing", "campaign"],
  "expires_at": "2025-12-31T23:59:59Z"
}

Response:

{
  "id": "abc123",
  "short_url": "https://urlyte.io/my-link",
  "original_url": "https://example.com/very-long-url",
  "custom_alias": "my-link",
  "title": "My Custom Link",
  "qr_code": "https://api.urlyte.io/qr/abc123",
  "created_at": "2025-01-07T10:30:00Z",
  "expires_at": "2025-12-31T23:59:59Z"
}

2. Get Link Analytics

Retrieve detailed analytics for any shortened link:

GET /links/{id}/analytics?period=30d

Response:
{
  "link_id": "abc123",
  "total_clicks": 1250,
  "unique_clicks": 890,
  "period": "30d",
  "clicks_by_date": [
    {"date": "2025-01-01", "clicks": 45},
    {"date": "2025-01-02", "clicks": 52}
  ],
  "top_countries": [
    {"country": "US", "clicks": 450},
    {"country": "UK", "clicks": 230}
  ],
  "top_referrers": [
    {"referrer": "twitter.com", "clicks": 320},
    {"referrer": "facebook.com", "clicks": 180}
  ],
  "devices": {
    "desktop": 60,
    "mobile": 35,
    "tablet": 5
  }
}

3. List All Links

Get a paginated list of all your shortened links:

GET /links?page=1&limit=50&sort=created_at&order=desc

Response:
{
  "links": [
    {
      "id": "abc123",
      "short_url": "https://urlyte.io/my-link",
      "original_url": "https://example.com/page",
      "title": "My Link",
      "clicks": 125,
      "created_at": "2025-01-07T10:30:00Z"
    }
  ],
  "pagination": {
    "current_page": 1,
    "total_pages": 5,
    "total_links": 250,
    "per_page": 50
  }
}

4. Update Link

Modify existing links (destination URL, title, expiration, etc.):

PUT /links/{id}

{
  "url": "https://example.com/updated-url",
  "title": "Updated Title",
  "description": "Updated description",
  "expires_at": "2025-06-30T23:59:59Z"
}

5. Delete Link

Permanently delete a shortened link:

DELETE /links/{id}

Response:
{
  "message": "Link deleted successfully",
  "deleted_at": "2025-01-07T15:30:00Z"
}

Code Examples

JavaScript/Node.js Example

const axios = require('axios');

const urlyteApi = axios.create({
  baseURL: 'https://api.urlyte.io/v1',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  }
});

// Create a short link
async function createShortLink(url, customAlias = null) {
  try {
    const response = await urlyteApi.post('/links', {
      url: url,
      custom_alias: customAlias,
      title: 'Generated via API'
    });

    console.log('Short URL:', response.data.short_url);
    return response.data;
  } catch (error) {
    console.error('Error:', error.response.data);
  }
}

// Get analytics
async function getAnalytics(linkId) {
  try {
    const response = await urlyteApi.get(`/links/${linkId}/analytics`);
    console.log('Total clicks:', response.data.total_clicks);
    return response.data;
  } catch (error) {
    console.error('Error:', error.response.data);
  }
}

// Usage
createShortLink('https://example.com/my-page', 'my-custom-link');
getAnalytics('abc123');

Python Example

import requests
import json

class UrlyteAPI:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_url = 'https://api.urlyte.io/v1'
        self.headers = {
            'Authorization': f'Bearer {api_key}',
            'Content-Type': 'application/json'
        }

    def create_link(self, url, custom_alias=None, title=None):
        data = {'url': url}
        if custom_alias:
            data['custom_alias'] = custom_alias
        if title:
            data['title'] = title

        response = requests.post(
            f'{self.base_url}/links',
            headers=self.headers,
            json=data
        )

        if response.status_code == 201:
            return response.json()
        else:
            raise Exception(f'API Error: {response.text}')

    def get_analytics(self, link_id, period='30d'):
        response = requests.get(
            f'{self.base_url}/links/{link_id}/analytics',
            headers=self.headers,
            params={'period': period}
        )

        if response.status_code == 200:
            return response.json()
        else:
            raise Exception(f'API Error: {response.text}')

# Usage
api = UrlyteAPI('YOUR_API_KEY')
link = api.create_link('https://example.com', 'my-link')
analytics = api.get_analytics(link['id'])

PHP Example

<?php
class UrlyteAPI {
    private $apiKey;
    private $baseUrl = 'https://api.urlyte.io/v1';

    public function __construct($apiKey) {
        $this->apiKey = $apiKey;
    }

    public function createLink($url, $customAlias = null, $title = null) {
        $data = ['url' => $url];
        if ($customAlias) $data['custom_alias'] = $customAlias;
        if ($title) $data['title'] = $title;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $this->baseUrl . '/links');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Authorization: Bearer ' . $this->apiKey,
            'Content-Type: application/json'
        ]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        if ($httpCode === 201) {
            return json_decode($response, true);
        } else {
            throw new Exception('API Error: ' . $response);
        }
    }

    public function getAnalytics($linkId, $period = '30d') {
        $url = $this->baseUrl . '/links/' . $linkId . '/analytics?period=' . $period;

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Authorization: Bearer ' . $this->apiKey
        ]);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $response = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        if ($httpCode === 200) {
            return json_decode($response, true);
        } else {
            throw new Exception('API Error: ' . $response);
        }
    }
}

// Usage
$api = new UrlyteAPI('YOUR_API_KEY');
$link = $api->createLink('https://example.com', 'my-link');
$analytics = $api->getAnalytics($link['id']);
?>

Webhooks

Urlyte supports webhooks to notify your application of events in real-time:

Supported Events

  • link.clicked: When someone clicks a shortened link
  • link.created: When a new link is created
  • link.updated: When a link is modified
  • link.deleted: When a link is deleted
  • link.expired: When a link reaches its expiration

Webhook Configuration

POST /webhooks

{
  "url": "https://your-app.com/webhook",
  "events": ["link.clicked", "link.created"],
  "secret": "your-webhook-secret"
}

Webhook Payload Example

{
  "event": "link.clicked",
  "timestamp": "2025-01-07T15:30:00Z",
  "data": {
    "link_id": "abc123",
    "short_url": "https://urlyte.io/my-link",
    "original_url": "https://example.com/page",
    "click_data": {
      "ip": "192.168.1.1",
      "user_agent": "Mozilla/5.0...",
      "referrer": "https://twitter.com",
      "country": "US",
      "device": "desktop"
    }
  }
}

SDKs and Libraries

To make integration even easier, we provide official SDKs for popular programming languages:

Official SDKs

  • JavaScript/Node.js: npm install urlyte-sdk
  • Python: pip install urlyte-python
  • PHP: composer require urlyte/php-sdk
  • Ruby: gem install urlyte-ruby
  • Go: go get github.com/urlyte/go-sdk

Community Libraries

Our community has created libraries for additional languages:

  • Java (Spring Boot integration)
  • C# (.NET Core)
  • Swift (iOS)
  • Kotlin (Android)

Rate Limits and Best Practices

Rate Limits

  • Free Plan: 1,000 requests per hour
  • Pro Plan: 10,000 requests per hour
  • Enterprise: Unlimited (with fair use policy)

Best Practices

  • Implement retry logic: Handle temporary failures gracefully
  • Cache responses: Store link data locally when appropriate
  • Use batch operations: Create multiple links in single requests when possible
  • Monitor rate limits: Check response headers for remaining quota
  • Secure API keys: Never expose keys in client-side code

Error Handling

The API uses standard HTTP status codes and provides detailed error messages:

// Error Response Format
{
  "error": {
    "code": "INVALID_URL",
    "message": "The provided URL is not valid",
    "details": "URL must include protocol (http:// or https://)"
  }
}

Common Error Codes

  • 400 Bad Request: Invalid request parameters
  • 401 Unauthorized: Invalid or missing API key
  • 403 Forbidden: Insufficient permissions
  • 404 Not Found: Link or resource not found
  • 429 Too Many Requests: Rate limit exceeded
  • 500 Internal Server Error: Server-side error

Start Building with Urlyte API

Get your API key and start integrating professional URL shortening into your applications today.

Support and Resources

Need help with the API? We're here to support your development:

  • Documentation: Comprehensive API reference at docs.urlyte.io
  • Code Examples: GitHub repository with sample implementations
  • Developer Support: Dedicated support channel for API questions
  • Community Forum: Connect with other developers using Urlyte
  • Status Page: Real-time API status and uptime monitoring

Conclusion

The Urlyte API provides a powerful, flexible way to integrate URL shortening into your applications. With comprehensive endpoints, detailed analytics, webhook support, and official SDKs, you have everything you need to build sophisticated link management features.

Whether you're building a simple link shortener or a complex marketing automation platform, Urlyte's API scales with your needs while maintaining reliability and performance.

Start exploring the API today and discover how easy it is to add professional URL shortening capabilities to your applications.