TrimLynk Docs

TrimLynk CLI

The official command-line interface for TrimLynk.

Architecture

The CLI is packaged with the official Python SDK and uses it as its sole API client:

text
TrimLynk CLI (`trimlynk`)
       ↓
Python SDK (`trimlynk`)
       ↓
Developer API v1
       ↓
TrimLynk Backend

No second HTTP client, custom curl wrappers, or duplicated API logic exist in the CLI. Authentication, retries, pagination, error parsing, and idempotency are provided directly by the SDK.

Quick Start

Installation

bash
pip install trimlynk

Authentication

Log in with your TrimLynk API key:

bash
trimlynk auth login

Credentials are saved automatically to your operating system's native secure keyring (Windows Credential Locker, macOS Keychain, or Linux Secret Service via FreeDesktop DBus) with a hardened 0600 file fallback.

Alternatively, provide the key via environment variable:

bash
export TRIMLYNK_API_KEY="tl_live_xxxxxxxxxxxxxxxxxxxxxxxx"

Verify authentication status:

bash
trimlynk auth status

Essential Commands

bash
# Create a link
trimlynk links create https://example.com --title "Homepage" --custom-slug home

# List links
trimlynk links list

# List in JSON format for scripting and jq
trimlynk links list --json

# Quiet mode (captures just the short URL for bash/zsh variables)
URL=$(trimlynk --quiet links create https://example.com)

# Workspace analytics summary
trimlynk analytics summary

# Manage campaigns
trimlynk campaigns list
trimlynk campaigns create --name "Launch 2026"

# Manage webhooks
trimlynk webhooks list
trimlynk webhooks deliveries <webhook-id>

Documentation

For full command documentation, arguments, CI/CD recipes, and exit codes, see TrimLynk CLI Reference.


TrimLynk Official CLI Reference

The official production-ready command-line interface for the TrimLynk developer platform. Built on the TrimLynk Python SDK, the CLI provides complete control over short links, analytics, conversions, marketing campaigns, and webhooks for developers and CI/CD pipelines.


1. Architecture

text
TrimLynk CLI (trimlynk)
     ↓
Python SDK (trimlynk)
     ↓
Developer API v1 (/api/v1/...)
     ↓
TrimLynk Backend Platform
  • Sole API Client: The CLI directly invokes the official trimlynk Python SDK (TrimLynk client). No second HTTP client or duplicate network layer exists inside the CLI.
  • Unified Engine: Retries, exponential backoff, rate limiting, HMAC verification, pagination iterators, and standardized error mappings are managed entirely through the SDK.

2. Installation

Install via pip:

bash
pip install trimlynk

Verify installation and entry point:

bash
trimlynk --version
# Output: trimlynk 1.0.0

trimlynk --help

3. Global Options

Global options can be placed at the root level, after the resource group, or after the leaf command:

OptionShorthandDescriptionDefault
--jsonOutput raw, unadorned JSON for scripting and jqfalse
--quiet-qSuppress tables; output only the primary resource ID/URLfalse
--api-keyExplicitly supply or override API key for this commandNone
--environmentEnvironment: live or testlive
--base-urlOverride API endpoint base URLhttps://api.trimlynk.com
--versionShow CLI version and exit
--help-hDisplay detailed command help and examples

Environment Variables

Environment variables are automatically recognized when CLI arguments are not provided:

VariableDescription
TRIMLYNK_API_KEYTrimLynk Developer API key
TRIMLYNK_ENVIRONMENTDefault environment (live or test)
TRIMLYNK_BASE_URLAPI base URL override
NO_COLOR / CIDisables terminal color output

Precedence Order: CLI Arguments (--api-key) > Environment Variables (TRIMLYNK_API_KEY) > OS Keyring > Fallback File (~/.trimlynk/credentials.json).


4. Authentication & Credential Storage

Security Guarantees

  • No Plaintext by Default: Credentials stored with trimlynk auth login use the operating system's native secure keyring (Windows Credential Locker, macOS Keychain, or Linux Secret Service via FreeDesktop DBus).
  • Hardened File Fallback: If an OS keyring is unavailable (e.g. headless containers), credentials fall back to ~/.trimlynk/credentials.json with user-only read/write permissions (chmod 600).
  • Never Leaked: Secrets are never echoed on typing, never printed to stdout/stderr in full, masked as tl_live_••••••••••••3456, never included in --json output, and excluded from exception diagnostics.

auth login

Prompts securely for an API key without echoing input, validates it against the live API, and securely saves it:

bash
trimlynk auth login

Or pass directly for script setups:

bash
trimlynk auth login --api-key tl_live_xxxxxxxxxxxxxxxxxxxxxxxx

auth status

Displays the current local authentication state:

bash
trimlynk auth status

Output:

text
Authenticated:   yes
Environment:     live
API Key:         tl_live_••••••••••••3456
Source:          system keyring (service=trimlynk)
Remote Status:   not checked
API Version:     1

Perform an active remote validation against the API:

bash
trimlynk auth status --check

auth logout

Removes stored credentials from the keyring and local fallback storage:

bash
trimlynk auth logout

5. Command Reference

Manage short links, custom aliases, and UTM campaign tags.

Shorten a destination URL:

bash
trimlynk links create https://example.com/products/summer \
  --title "Summer Campaign Landing" \
  --custom-slug summer26 \
  --tag marketing \
  --tag promo \
  --utm-source newsletter \
  --utm-medium email \
  --utm-campaign summer_sale \
  --idempotency-key idem_link_create_001

List links with pagination and filtering:

bash
trimlynk links list --page 1 --limit 25 --sort clicks --tag marketing

Stream all links across all pages safely:

bash
trimlynk links list --all

Retrieve complete details and telemetry for a single link:

bash
trimlynk links get clk_xyz123

Update link destination, title, slug, or activation state:

bash
trimlynk links update clk_xyz123 \
  --title "Updated Summer Landing" \
  --inactive

Delete a short link:

bash
# Interactive prompt (requires typing y/N)
trimlynk links delete clk_xyz123

# Automation / non-interactive (bypasses prompt)
trimlynk links delete clk_xyz123 --yes

Analytics (trimlynk analytics)

Retrieve aggregated telemetry and link performance data directly from the server.

analytics summary

Workspace-wide analytics overview:

bash
trimlynk analytics summary \
  --start-date 2026-09-01T00:00:00Z \
  --end-date 2026-09-24T23:59:59Z

Telemetry for a specific link:

bash
trimlynk analytics link clk_xyz123 \
  --start-date 2026-09-01T00:00:00Z \
  --end-date 2026-09-24T23:59:59Z

Conversions (trimlynk conversions)

Record and query conversion events and attribution funnels.

conversions create

Record a new conversion event:

bash
trimlynk conversions create \
  --url-id lnk_abc123 \
  --event-name purchase \
  --event-value 49.99 \
  --currency USD \
  --order-id ord_98765 \
  --customer-email user@example.com

conversions list

List conversion events:

bash
trimlynk conversions list --page 1 --limit 50 --event-name purchase

conversions get

Inspect conversion event details:

bash
trimlynk conversions get cnv_abc789

Campaigns (trimlynk campaigns)

Organize links and attribution into marketing campaigns.

campaigns create

bash
trimlynk campaigns create \
  --name "Q4 Global Launch" \
  --description "Worldwide Q4 promotional drive" \
  --utm-source google \
  --utm-medium cpc \
  --utm-campaign q4_launch \
  --idempotency-key idem_camp_q4

campaigns list

bash
trimlynk campaigns list --page 1 --limit 20

campaigns get

bash
trimlynk campaigns get cmp_001

campaigns update

bash
trimlynk campaigns update cmp_001 --name "Q4 Global Launch (Extended)"

campaigns delete

bash
trimlynk campaigns delete cmp_001 --yes

Webhooks (trimlynk webhooks)

Register and manage webhook endpoints for real-time notifications.

webhooks create

Register a webhook endpoint:

bash
trimlynk webhooks create \
  --url https://api.mycompany.com/webhooks/trimlynk \
  --event link.created \
  --event click.created \
  --description "Production event ingestion" \
  --idempotency-key idem_whk_01

Security Notice: If the server generates a signing secret, the CLI displays it once upon creation. It is never exposed or re-displayed afterwards.

webhooks list

bash
trimlynk webhooks list

webhooks get

bash
trimlynk webhooks get whk_999

webhooks update

bash
trimlynk webhooks update whk_999 --url https://new-api.mycompany.com/webhook --active

webhooks delete

bash
trimlynk webhooks delete whk_999 --yes

webhooks test

Dispatch a ping test event to the endpoint:

bash
trimlynk webhooks test whk_999

webhooks deliveries

Inspect delivery logs for troubleshooting:

bash
trimlynk webhooks deliveries whk_999 --page 1 --limit 20

webhooks retry

Re-dispatch a failed webhook delivery:

bash
trimlynk webhooks retry whk_999 del_888

Configuration (trimlynk config)

Manage local CLI defaults stored in ~/.trimlynk/config.json.

bash
# View configuration
trimlynk config get

# Inspect specific setting
trimlynk config get environment

# Update setting
trimlynk config set environment test
trimlynk config set base_url https://api.trimlynk.com

6. Output Modes & Scripting

JSON Mode (--json)

Every command supports --json. Output is strictly valid JSON without ANSI color codes or decorative text.

bash
trimlynk links list --json | jq '.data[].short_url'

Quiet Mode (-q / --quiet)

Quiet mode extracts only the essential identifier (e.g. URL or ID), ideal for shell variables:

bash
# Create a link and capture short URL directly into a shell variable
SHORT_URL=$(trimlynk -q links create https://example.com/docs --title "Docs")
echo "Generated URL: $SHORT_URL"

7. Exit Codes

The CLI strictly maps all outcomes and SDK exceptions into standardized POSIX exit codes:

Exit CodeMeaningTypical Cause
0SuccessCommand executed successfully
1General ErrorUnhandled exception or unexpected failure
2Invalid Arguments / RequestMissing argument, invalid syntax, or API 400 validation error
3Authentication ErrorMissing API key, invalid key, or expired credentials (401)
4Permission ErrorInsufficient API key scope or workspace permission (403)
5Not FoundSpecified resource ID or custom slug does not exist (404)
6Rate LimitedRequest quota or velocity threshold exceeded (429)
7API / Server ErrorConflict (409), idempotency collision, or server error (500)
8Network / Timeout ErrorConnection refused, DNS failure, or socket timeout

8. CI/CD & Automation Examples

GitHub Actions

yaml
name: Deploy & Generate Short Links

on:
  push:
    branches: [main]

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.12'

      - name: Install TrimLynk CLI
        run: pip install trimlynk

      - name: Create Release Link
        env:
          TRIMLYNK_API_KEY: ${{ secrets.TRIMLYNK_API_KEY }}
        run: |
          RELEASE_URL=$(trimlynk --quiet links create \
            "https://github.com/${{ github.repository }}/releases/tag/${{ github.ref_name }}" \
            --title "Release ${{ github.ref_name }}" \
            --custom-slug "v-${{ github.ref_name }}")
          echo "Public release link: $RELEASE_URL"

Shell Automation with jq

bash
#!/usr/bin/env bash
set -euo pipefail

# Ensure credentials exist
export TRIMLYNK_API_KEY="${TRIMLYNK_PROD_KEY}"

# Export all link IDs with > 100 clicks
trimlynk links list --all --json | \
  jq -r '.data[] | select(.clicks > 100) | "\(.id)\t\(.short_url)\t\(.clicks)"'

9. Shell Completion

To generate command completions for your shell using argcomplete (optional extension):

bash
# Bash
eval "$(register-python-argcomplete trimlynk)"

# Zsh
autoload -U +X bashcompinit && bashcompinit
eval "$(register-python-argcomplete trimlynk)"