Create Short Link

POST /v2/external/client/short-links uses a workspace-bound X-API-Key. The dashboard equivalent is POST /v2/short-links/create with a user session/Bearer token. Anonymous creation is limited to the primary domain.

Safe retries

Send Idempotency-Key: <unique-operation-id> for each logical creation. Keep the same key and body when retrying a timeout. A completed replay returns the original link without another quota reservation. Without this header, each request creates a new link, even for the same destination.

Keys contain 1–128 ASCII letters, digits, ., _, :, or -. Scope is the actor (source IP for anonymous callers), workspace and domain. Reusing a key with a different body returns 409. Deleted creations cannot be replayed into new links. Keep keys unique; there is no automatic expiration while the record exists. An anonymous client behind a shared IP should use a random UUID per operation.

Request

curl --request POST "$YLNK_API_ORIGIN/v2/external/client/short-links" \
  --header "X-API-Key: $YLNK_API_KEY" \
  --header 'Idempotency-Key: launch-2026-001' \
  --header 'Content-Type: application/json' \
  --data '{
    "originalUrl": "https://example.com/catalog",
    "customUrl": "summer-sale",
    "domainId": "YOUR_ACTIVE_DOMAIN_ID",
    "title": "Summer catalog",
    "routingConfig": {
      "platformTargeting": [{"platform": "ANDROID", "url": "https://play.google.com/store/apps/details?id=com.example.app"}]
    }
  }'

Set YLNK_API_ORIGIN to your deployment API origin. Keep API keys on your server, never in public browser code.

Field Required Meaning
originalUrl Yes Public HTTP(S) destination; whitespace at its ends is trimmed
customUrl No Alias: 1–24 ASCII letters/digits/underscores/hyphens; reserved routes and deleted_ prefixes are rejected
domainId No ID from domain management, not a hostname; omit/null for primary domain
title No Merchant/editor label
category, categoryTitle, categoryValue No Classification metadata
linkFolioProfileId No Optional profile association; not domain configuration
routingConfig No Platform rules and/or rotation; see below

Custom domain requirements

The domain must belong to the API key's workspace (or permitted legacy personal ownership), have ACTIVE status and purpose SHORT_LINK or APP_LINK. PENDING, VERIFIED or SSL_PENDING is insufficient. Domain registration and verification require dashboard authentication; an API key does not grant those endpoints.

The same alias can exist on different domains. Within a domain it is case-sensitive and must not collide with a live link, historical alias or deleted code. Existing 4-character links remain valid. Newly generated codes have 7 case-sensitive alphanumeric characters. Never validate response codes as fixed-length or treat IDs as MongoDB ObjectIds; idempotent IDs are opaque strings.

Response

HTTP 200, including a successful replay. Example shows selected fields:

{
  "status": true,
  "message": "Short link created successfully",
  "data": {
    "id": "opaque-link-id",
    "shortUrl": "summer-sale",
    "originalUrl": "https://example.com/catalog",
    "domainId": "YOUR_ACTIVE_DOMAIN_ID",
    "isActive": true,
    "isCustomUrl": true,
    "routingConfig": {
      "platformTargeting": [{"platform": "ANDROID", "url": "https://play.google.com/store/apps/details?id=com.example.app"}]
    }
  }
}

shortUrl is the code, not an absolute URL. For a configured host links.example.com, build https://links.example.com/summer-sale. Store id for updates and analytics; it avoids ambiguity when codes repeat on different domains. External responses omit passwords, requester IPs and internal request hashes.

Routing

Platform values: IOS, ANDROID, MACOS, WINDOWS, LINUX, MOBILE, DESKTOP. At most 16 platform entries, one per platform. Platform targeting precedes rotation. Advanced routing at redirect time is paid-plan gated.

{
  "rotation": {
    "mode": "WEIGHTED_RANDOM",
    "links": [
      {"url": "https://example.com/a", "weight": 2},
      {"url": "https://example.com/b", "weight": 1}
    ]
  }
}

Rotation allows 1–32 destinations with positive integer weights; total ≤ 2147483647. Weights are relative, so 2:1 means approximately 67%:33%. SEQUENTIAL is best-effort per instance, not globally ordered. All default, platform, rotation and supplied fallbackUrl destinations pass the same URL safety checks. The platform fallbackUrl field is accepted/validated but the short-link router does not detect whether an app is installed or automatically use it. Use the dedicated deep-link APIs for app-opening flows.

Errors and retry policy

Status Meaning Client action
400 Invalid alias, destination, routing or domain configuration Correct the input
401 / 403 Authentication/permission failure Check API key and workspace permissions
409 Alias taken, ambiguous reference, changed/deleted idempotent request, or allocation retry limit Correct permanent conflicts; retry allocation contention with bounded backoff
406 Subscription quota rejection (current API contract) Review workspace plan/usage
429 Request or anonymous creation limit reached Back off; honor retry headers when provided
5xx / timeout Server/transport failure Retry the same key/body with bounded exponential backoff and jitter

No permanent retry loop or polling job is needed. During a concurrent in-flight retry, the first request may not yet be visible; retry once it completes. Quota limits are enforced through atomic counter updates; normal insert failures refund the exact reservation. Counter reservation and link insertion are separate MongoDB operations, so abrupt process termination or an ambiguous database failure can require usage reconciliation. This is not a multi-document transaction guarantee.