TrimLynk Docs

TrimLynk Developer API & API Key Architecture

The TrimLynk Developer API (/api/v1/developer/*) enables software developers, DevOps teams, and automation bots to programmatically manage shortened links, inspect click analytics, extract conversion funnels, manage marketing campaigns, and configure real-time webhooks without exposing interactive browser session tokens or cookies.


1. Authentication & Security

Header Format

All Developer API endpoints require authentication using a cryptographically secure API key passed via the standard Authorization header:

http
Authorization: Bearer tl_live_58c20eb076fa968840c83a19b8...

Alternatively, you can provide the key via the x-api-key header:

http
x-api-key: tl_live_58c20eb076fa968840c83a19b8...

Key Formats & Environments

API keys are prefixed based on their environment:

  • Live Environment: tl_live_<entropy> (Default for production link creation & live traffic)
  • Test Environment: tl_test_<entropy> (For staging, QA, and CI test pipelines)
  • Legacy Keys: tk_live_<entropy> (Maintained for backwards compatibility)

Storage & Security

  • One-Time Secret Reveal: The raw secret key is displayed only once upon generation or regeneration (POST /api/v1/keys/:id/regenerate). TrimLynk never stores raw keys.
  • SHA-256 Hashing: Stored keys are irreversibly hashed using SHA-256 prior to database persistence.
  • Constant-Time Verification: Comparison prevents timing attacks.
  • Anti-Enumeration 401s: Requests with invalid, revoked, disabled, or expired keys all receive a generic 401 error response to prevent key existence enumeration:
    json
    {
      "error": {
        "code": "invalid_api_key",
        "message": "The API key is invalid or expired."
      }
    }

2. Granular Scopes & Permissions

Keys support least-privilege scoping:

ScopeDescription
links:readList links, search tags, retrieve link metadata
links:writeShorten URLs, customize slugs, update destinations, delete links
analytics:readRead aggregate click metrics, geographic, device, and referrer stats
conversions:readRead conversion events, revenue attribution, and funnel metrics
campaigns:readList and retrieve campaign folders
campaigns:writeCreate, update, or archive marketing campaigns
webhooks:readInspect webhook endpoints and delivery attempt logs
webhooks:writeRegister webhook endpoints, update event triggers, fire test pings
* / adminFull administrative API access across all resources

If a key lacks the necessary scope for an operation, the API returns HTTP 403:

json
{
  "error": {
    "code": "forbidden",
    "message": "You do not have permission to perform this action. Required scope: links:write"
  }
}

3. Standard Response Formats & Request Tracing

Request Tracing & Version Headers

Every Developer API response includes deterministic headers:

  • X-Request-Id: Unique request trace identifier (e.g., req_01925b42a98f). If the client provides a valid X-Request-Id, it is preserved; otherwise it is auto-generated.
  • X-Trimlynk-API-Version: Declares the API version contract (currently 1).
  • Idempotency-Key (Optional): Supported on mutating endpoints (POST /links, POST /campaigns, POST /webhooks). When replayed, the response carries Idempotent-Replay: true. See Idempotency Guide.

Single Resource Envelope

json
{
  "data": {
    "id": "cm7...",
    "originalUrl": "https://example.com/promo",
    "shortUrl": "k9xL2a",
    "shortLink": "https://trimlynk.com/k9xL2a",
    "clicks": 42
  },
  "requestId": "req_01925b42a98f"
}

Paginated Collections

Default limit is 50, maximum limit is 100.

json
{
  "data": [ ... ],
  "pagination": {
    "page": 1,
    "limit": 50,
    "total": 85,
    "totalPages": 2
  },
  "requestId": "req_01925b42a98f"
}

Standard Error Envelope

All error responses consistently return structured error categories without exposing stack traces or database internals:

json
{
  "error": {
    "code": "validation_error",
    "message": "Field 'originalUrl' is required.",
    "details": {
      "field": "originalUrl"
    }
  },
  "requestId": "req_01925b42a98f"
}

Error Categories:

  • invalid_request (400)
  • validation_error (400)
  • invalid_api_key (401)
  • insufficient_scope (403)
  • not_found (404)
  • conflict (409)
  • idempotency_conflict (409)
  • rate_limit_exceeded (429)
  • internal_error (500)

See API Versioning Policy and Idempotency Guide.


4. API Endpoints Reference

POST /api/v1/developer/links
Scope: links:write

bash
curl -X POST "https://trimlynk.com/api/v1/developer/links" \
  -H "Authorization: Bearer tl_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "originalUrl": "https://stripe.com/checkout/sessions/xyz",
    "customSlug": "black-friday",
    "title": "Black Friday Special",
    "tags": ["promo", "2026"],
    "utmSource": "newsletter",
    "utmCampaign": "bf2026"
  }'

GET /api/v1/developer/links?page=1&limit=20&search=promo&sort=clicks
Scope: links:read

GET /api/v1/developer/links/:id (accepts UUID, shortUrl, or customSlug)
Scope: links:read

PATCH /api/v1/developer/links/:id
Scope: links:write

DELETE /api/v1/developer/links/:id
Scope: links:write


4.2 Analytics & Conversion Funnel API

Aggregate Workspace Analytics

GET /api/v1/developer/analytics?startDate=2026-01-01&endDate=2026-12-31
Scope: analytics:read

Returns total clicks, devices, countries, and top referrers.

GET /api/v1/developer/analytics/links/:id
Scope: analytics:read

Conversion Funnel Metrics

GET /api/v1/developer/analytics/conversions?urlId=...
Scope: conversions:read or analytics:read

Returns Click → Lead → Sale funnel metrics:

json
{
  "data": {
    "clicks": 1250,
    "leads": 125,
    "sales": 25,
    "revenue": 3499.50,
    "clickToLeadRate": 10.0,
    "leadToSaleRate": 20.0,
    "clickToSaleRate": 2.0,
    "revenuePerClick": 2.80,
    "averageOrderValue": 139.98
  }
}

4.3 Conversions API

Record Conversion Event

POST /api/v1/developer/conversions
Scope: conversions:write

bash
curl -X POST "https://trimlynk.com/api/v1/developer/conversions" \
  -H "Authorization: Bearer tl_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: idem_conv_12345" \
  -d '{
    "urlId": "lnk_abc123",
    "eventName": "purchase",
    "eventValue": 49.99,
    "currency": "USD",
    "orderId": "ord_98765",
    "customerEmail": "customer@example.com"
  }'

List Conversions

GET /api/v1/developer/conversions?page=1&limit=25&eventName=purchase
Scope: conversions:read

Get Conversion Event

GET /api/v1/developer/conversions/:id
Scope: conversions:read


4.4 Campaigns API

List Campaigns

GET /api/v1/developer/campaigns
Scope: campaigns:read

Create Campaign

POST /api/v1/developer/campaigns
Scope: campaigns:write

bash
curl -X POST "https://trimlynk.com/api/v1/developer/campaigns" \
  -H "Authorization: Bearer tl_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Q3 Enterprise Outreach",
    "description": "Targeted B2B campaign",
    "goal": 5000,
    "budget": 2500,
    "status": "active"
  }'

Get, Update, or Delete Campaign

  • GET /api/v1/developer/campaigns/:id (campaigns:read)
  • PATCH /api/v1/developer/campaigns/:id (campaigns:write)
  • DELETE /api/v1/developer/campaigns/:id (campaigns:write)

4.5 Webhooks API

List Registered Webhooks

GET /api/v1/developer/webhooks
Scope: webhooks:read

Register Webhook Endpoint

POST /api/v1/developer/webhooks
Scope: webhooks:write

bash
curl -X POST "https://trimlynk.com/api/v1/developer/webhooks" \
  -H "Authorization: Bearer tl_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://api.yourdomain.com/webhooks/trimlynk",
    "events": ["click.created", "conversion.created", "link.created"],
    "description": "Production sync service"
  }'

Note: Returns the webhook signing secret whsec_... once upon creation.

Test Webhook

POST /api/v1/developer/webhooks/:id/test
Scope: webhooks:write

Dispatches an immediate ping event to verify your server's HMAC SHA-256 signature verification.

Inspect Delivery History

GET /api/v1/developer/webhooks/:id/deliveries
Scope: webhooks:read

Retry Webhook Delivery Attempt

POST /api/v1/developer/webhooks/:id/deliveries/:deliveryId/retry
Scope: webhooks:write

Retries a previously failed webhook delivery, preserving the original event payload and generating a fresh timestamped HMAC signature.


5. Rate Limits & Performance

  • Rate Limit Window: 1 Hour (rolling).
  • Default Developer Quota: 100 requests / hour on Render container free tier, up to 5,000 requests / hour for enterprise configurations.
  • Throttled Metadata Updates: lastUsedAt is updated asynchronously with a 60-second debounce to minimize database write amplification.
  • Audit Logging: Every API key request writes an execution record (ApiKeyLog) including response time and status code for observability.

6. Official SDKs & CLI Tools

Ready to test in your workspace?

Manage API keys, live webhooks, and request telemetry in the TrimLynk Developer Console.

Open Interactive OpenAPI Studio