TrimLynk API Idempotency Guide
1. Overview
Network failures, socket drops, and server timeouts can cause client applications to retry mutating requests without knowing whether the original request succeeded. Without idempotency, duplicate calls can result in duplicate links, multiple campaigns, or redundant webhooks.
TrimLynk supports production-grade Idempotency on key mutating operations using the standard Idempotency-Key HTTP header.
2. Supported Mutating Endpoints
Idempotency is supported on the following Developer API endpoints:
| Method | Endpoint | Description |
|---|---|---|
POST | /api/v1/developer/links | Link shortening & custom slug creation |
POST | /api/v1/developer/campaigns | Marketing campaign / folder creation |
POST | /api/v1/developer/webhooks | Webhook subscription registration |
3. How It Works
The Idempotency-Key Header
Send a unique token in the Idempotency-Key request header:
Idempotency-Key: order_123_link_creationYou can use UUIDs, order numbers, transaction references, or any unique string up to 256 characters.
Practical curl Example
curl -X POST \
https://api.trimlynk.com/api/v1/developer/links \
-H "Authorization: Bearer tl_live_xxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order_123_link" \
-d '{
"originalUrl": "https://example.com/products/headphones",
"title": "Summer Campaign Link"
}'4. Execution Scenarios
Scenario A: First Request (Success)
- The server checks if
order_123_linkexists for your API key. - Since it does not exist, an atomic reservation is created with status
processing. - The resource is created and returned with HTTP 201:
json
{ "data": { "id": "cm7123abc", "originalUrl": "https://example.com/products/headphones", "shortUrl": "h8xK9", "shortLink": "https://trimlynk.com/h8xK9", "clicks": 0 }, "requestId": "req_01925b42a98f" } - The status code and response payload are safely persisted.
Scenario B: Automatic Retry / Duplicate Request (Replay)
If your client retries the exact same request with the same Idempotency-Key:
- The server verifies that the request payload hash matches the original request.
- The server returns the cached response without creating a new resource or incrementing database counters.
- The response carries the
Idempotent-Replay: trueheader:httpHTTP/1.1 201 Created Idempotent-Replay: true X-Request-Id: req_01925b42a98f X-Trimlynk-API-Version: 1json{ "data": { "id": "cm7123abc", "originalUrl": "https://example.com/products/headphones", "shortUrl": "h8xK9", "shortLink": "https://trimlynk.com/h8xK9", "clicks": 0 }, "requestId": "req_01925b42a98f" }
Scenario C: Same Key + Different Request Body (Conflict)
If you reuse an Idempotency-Key with a different payload:
curl -X POST \
https://api.trimlynk.com/api/v1/developer/links \
-H "Authorization: Bearer tl_live_xxxxxxxxxxxxxxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: order_123_link" \
-d '{
"originalUrl": "https://different-site.com"
}'- The server detects that the payload hash does not match the original transaction.
- The server returns HTTP 409 Conflict:
json
{ "error": { "code": "idempotency_conflict", "message": "The Idempotency-Key was already used with a different request." }, "requestId": "req_01925b42a990" }
Scenario D: Concurrent Requests
If two network connections arrive simultaneously with the same Idempotency-Key:
- The first connection acquires an atomic database lock (
status: "processing"). - The second connection detects the in-flight state and waits (polling every 100ms for up to 3 seconds) for the first connection to finish.
- Once the first request completes, the second connection receives the replayed result.
- Under high concurrency races, duplicate records are strictly prevented by the database constraint
@@unique([apiKeyId, idempotencyKey]).
Scenario E: Key Expiration & TTL
- Idempotency records are retained for 24 hours by default (
API_IDEMPOTENCY_TTL_HOURS=24). - After 24 hours, expired records are purged automatically by a background worker.
- Reusing an idempotency key after 24 hours is treated as a new request.
5. Security & Isolation
- API Key Isolation: Idempotency keys are strictly scoped per API key (
apiKeyId). If Key A and Key B use the same stringorder_123, they are completely isolated and will never collide or access each other's data. - Workspace Isolation: Even within the same workspace, different API keys maintain distinct idempotency namespaces.
- Zero Secret Exposure: Request hashes exclude sensitive credentials, API keys, passwords, and webhook secrets. Plaintext request bodies are never stored in the idempotency log.
TrimLynk API Versioning & Evolution Policy
1. Versioning Contract
TrimLynk employs an explicit, deterministic API versioning strategy designed for long-term backward compatibility and seamless developer experience across official SDKs and automated pipelines.
Current Stable Version: v1
The current stable API version is v1.
- Base path:
/api/v1/developer/*(or/v1/developer/*) - Response header: All responses from version 1 endpoints emit the following header:
http
X-Trimlynk-API-Version: 1
2. URL Path and Routing
- Versioned Path: Clients must target
/api/v1/developer/*for guaranteed compatibility. - Future Versions: When major breaking schema changes require a new contract, TrimLynk will introduce
/api/v2/developer/*while keeping/api/v1/*fully functional in parallel. - Unversioned Fallbacks: Requests to legacy unversioned paths (e.g.
/api/*) operate as backward-compatible proxies to the active v1 router.
3. Deprecation and Sunset Strategy
TrimLynk follows standard IETF RFC 8594 / RFC 9285 policies when deprecating endpoints or parameters:
Deprecation Response Headers
When an endpoint is marked for future retirement, responses include:
Deprecation: true
Sunset: Wed, 11 Nov 2026 00:00:00 GMT
Link: <https://trimlynk.com/docs/api/migration>; rel="deprecation"Deprecation: Declares that the resource or API version has entered the deprecation period.Sunset: Defines the precise HTTP date/time after which the resource will become unavailable or return410 Gone.Link: Provides a direct hyperlink to the migration guide and breaking change changelog.
Grace Period Policy
- Core endpoints have a minimum 180-day deprecation grace period prior to turn-down.
- Non-breaking additions (new response attributes, optional query parameters) are released continuously without bumping the major API version.
4. Client Best Practices
- Always Read Headers: Monitor
X-Request-Idfor tracing and logDeprecationwarnings in CI pipelines. - Strict Request IDs: Pass an
X-Request-Idheader with every outgoing mutation to correlate client logs with TrimLynk server telemetry. - Handle 410 Gone and 429: Respect
Retry-Afterheaders on rate limits and plan upgrades according to the Sunset timeline.