Skip to content

URL Shortener API Guide: Build Branded Short Links at Scale (2026)

A developer guide to URL shortener APIs — covering authentication, link creation, analytics retrieval, bulk operations, and geo-targeted redirects. With CDNZero API examples in JavaScript, Python, and curl.

GuideAug 25, 2026 · 8 min read

A URL shortener API sounds trivial until you're building something that needs to create thousands of branded short links, track clicks by geography, or redirect users differently based on their device. This guide walks through the real API surface you need for production use.

Authentication

Every CDNZero API request uses Bearer token authentication. Generate your API key from the dashboard under Settings → API Keys. Tokens are scoped — you can create read-only tokens for analytics and read-write tokens for link management.

bash
curl -X POST https://api.cdnzero.com/v1/links \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/very/long/path"}'

Creating a short link

The link creation endpoint accepts a destination URL and optional parameters: a custom slug, an expiry timestamp, geo-redirect rules, and device-targeting rules.

javascript
const response = await fetch("https://api.cdnzero.com/v1/links", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.CDNZERO_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    url: "https://example.com/landing-page",
    slug: "summer-sale",         // optional custom slug
    expires_at: "2026-12-31",    // optional expiry
  }),
});

const link = await response.json();
console.log(link.short_url); // https://cdn0.to/summer-sale

Retrieving analytics

The analytics endpoint returns click counts, unique visitors, top countries, top referrers, and device breakdown. All analytics are queryable by date range.

python
import requests

headers = {"Authorization": f"Bearer {API_KEY}"}
params = {"from": "2026-01-01", "to": "2026-10-01"}

r = requests.get(
    "https://api.cdnzero.com/v1/links/summer-sale/analytics",
    headers=headers,
    params=params,
)
data = r.json()
print(data["clicks"])       # total clicks
print(data["countries"])    # [{"code": "US", "clicks": 1204}, ...]

Bulk link creation

For campaigns that need hundreds or thousands of unique links — QR codes in print, personalised email links, per-user tracking — use the bulk endpoint. It accepts up to 1,000 links per request and returns the created short URLs in the same order.

javascript
const links = users.map((user) => ({
  url: `https://example.com/welcome?ref=${user.id}`,
  slug: `u-${user.id}`,
}));

const response = await fetch("https://api.cdnzero.com/v1/links/bulk", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.CDNZERO_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ links }),
});

Geo-targeted redirects

Redirect users to different destinations based on their country. Useful for localised landing pages, region-specific pricing, or compliance requirements.

javascript
{
  "url": "https://example.com/en/default",
  "geo_redirects": [
    { "country": "DE", "url": "https://example.com/de/landing" },
    { "country": "FR", "url": "https://example.com/fr/landing" },
    { "country": "JP", "url": "https://example.com/ja/landing" }
  ]
}

Rate limits and quotas

The API is rate-limited to 100 requests per minute on the free plan and 1,000 per minute on Pro. Bulk operations count as one request regardless of link count. If you exceed the rate limit, the API returns a 429 with a Retry-After header.

Start hosting files the simple way

Create a workspace, upload your first asset and copy its CDN URL. The free plan includes 3 GB of storage and 15 GB of transfer.

No credit card required · Cancel anytime