Links API Endpoints
The Links API exposes deterministic operations to create, inspect, update, and delete short links with support for device-targeted smart routing, geofencing, password gating, and expiration.
1. Create a Short Link
Create a new short link under the active workspace with optional smart routing parameters.
POST /api/v1/links
Request Headers
Authorization: Bearer <token>
Content-Type: application/jsonRequest Body Parameters
The request body is validated against CreateLinkSchema in shared/schemas/link.ts.
| Field | Type | Required | Description |
|---|---|---|---|
url |
string |
Yes | Destination target URL. Must be valid http:// or https:// protocol (max 2,048 characters). |
slug |
string |
No | Custom short alias (1-2048 characters). Must match /^[a-zA-Z0-9_-]+$/. Defaults to random alphanumeric nanoid. |
customDomain |
string |
No | Target custom domain hostname (e.g. link.brand.com). If omitted, uses the workspace default or shaf.is. |
customDomainId |
string |
No | Internal identifier of a custom domain registered to this workspace. |
title |
string |
No | OpenGraph and link card title (max 256 characters). |
description |
string |
No | OpenGraph description meta tag content (max 2,048 characters). |
image |
string |
No | OpenGraph preview image asset URL or identifier (max 128 characters). |
apple |
string |
No | iOS target redirect URL for Apple devices (max 2,048 characters). |
google |
string |
No | Android target redirect URL for Google Play / Android devices (max 2,048 characters). |
geo |
record |
No | Key-value mapping of ISO 3166-1 alpha-2 uppercase country codes to regional target URLs (e.g. {"US": "https://us.example.com", "DE": "https://de.example.com"}). |
tags |
string[] |
No | Array of category tags (max 10 tags, 1-32 chars each, auto-converted to lowercase). |
password |
string |
No | Plaintext password to gate access (1-128 characters). Masks with **** in console reads. |
expiration |
integer |
No | Unix timestamp in seconds when link terminates resolution. Must be in the future. |
cloaking |
boolean |
No | When true, masks target URL via edge iframe or HTML masking instead of HTTP 308 redirect. |
redirectWithQuery |
boolean |
No | When true, preserves and forwards incoming URL query strings to the destination. |
autoLinkKey |
string |
No | Unique identifier for dynamic auto-linking and client keyword substitution (max 128 characters). |
unsafe |
boolean |
No | Administrative override to bypass destination safety and Google Safe Browsing heuristics. |
comment |
string |
No | Internal workspace notes or operational memo (max 2,048 characters). |
Request Example
curl -X POST "https://shaf.app/api/v1/links" \
-H "Authorization: Bearer $SHAF_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/checkout",
"slug": "summer-promo",
"customDomain": "link.brand.com",
"title": "Summer Sale 2026",
"tags": ["promo", "summer"],
"apple": "https://apps.apple.com/app/id123456789",
"google": "https://play.google.com/store/apps/details?id=com.brand.app",
"geo": {
"GB": "https://uk.example.com/checkout",
"DE": "https://de.example.com/checkout"
},
"expiration": 1782864000,
"redirectWithQuery": true
}'const token = process.env.SHAF_API_TOKEN;
const response = await fetch("https://shaf.app/api/v1/links", {
method: "POST",
headers: {
"Authorization": `Bearer ${token}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com/checkout",
slug: "summer-promo",
customDomain: "link.brand.com",
title: "Summer Sale 2026",
tags: ["promo", "summer"],
apple: "https://apps.apple.com/app/id123456789",
google: "https://play.google.com/store/apps/details?id=com.brand.app",
geo: {
GB: "https://uk.example.com/checkout",
DE: "https://de.example.com/checkout",
},
expiration: 1782864000,
redirectWithQuery: true,
}),
});
const result = await response.json();
console.log(result.data);Response (HTTP 201 Created)
{
"code": 0,
"data": {
"id": "lnk_39dfa01e8b",
"slug": "summer-promo",
"url": "https://example.com/checkout",
"customDomain": "link.brand.com",
"title": "Summer Sale 2026",
"tags": ["promo", "summer"],
"apple": "https://apps.apple.com/app/id123456789",
"google": "https://play.google.com/store/apps/details?id=com.brand.app",
"geo": {
"GB": "https://uk.example.com/checkout",
"DE": "https://de.example.com/checkout"
},
"expiration": 1782864000,
"redirectWithQuery": true,
"createdAt": 1774180000,
"updatedAt": 1774180000
}
}2. List Short Links
Retrieve paginated short links belonging to the workspace with optional filtering by tag, domain, or search keyword.
GET /api/v1/links
Query Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
limit |
integer |
50 |
Maximum number of records to return (1-100). |
offset |
integer |
0 |
Number of records to skip for offset-based pagination. |
cursor |
string |
— | Opaque cursor token for cursor-based pagination. |
search |
string |
— | Search filter matching slug, destination URL, title, or comment. |
tag |
string |
— | Filter by specific tag name. |
domain |
string |
— | Filter by custom domain hostname. |
Response Example (HTTP 200 OK)
{
"code": 0,
"data": {
"items": [
{
"id": "lnk_39dfa01e8b",
"slug": "summer-promo",
"url": "https://example.com/checkout",
"customDomain": "link.brand.com",
"title": "Summer Sale 2026",
"tags": ["promo", "summer"],
"createdAt": 1774180000,
"updatedAt": 1774180000
}
],
"total": 1,
"hasMore": false
}
}3. Retrieve Link by Slug
Fetch link definition, routing rules, and metadata for a specific slug.
GET /api/v1/links/:slug
Path Parameters
slug(string, required): The short link identifier (e.g.summer-promo).
Query Parameters
domain(string, optional): Scopes lookup to a specific custom domain if the slug exists across multiple hostnames.
Response Example (HTTP 200 OK)
{
"code": 0,
"data": {
"id": "lnk_39dfa01e8b",
"slug": "summer-promo",
"url": "https://example.com/checkout",
"customDomain": "link.brand.com",
"title": "Summer Sale 2026",
"tags": ["promo", "summer"],
"apple": "https://apps.apple.com/app/id123456789",
"google": "https://play.google.com/store/apps/details?id=com.brand.app",
"redirectWithQuery": true,
"createdAt": 1774180000,
"updatedAt": 1774180000
}
}4. Update / Patch a Link
Modify destination URL, metadata, smart routing attributes, or expiration of an existing short link.
PATCH /api/v1/links/:slug (or PUT /api/v1/links/:slug)
Request Body Parameters
Accepts a partial object adhering to EditLinkSchema in shared/schemas/link.ts.
| Field | Type | Description |
|---|---|---|
url |
string |
New destination target URL. |
title |
string |
Updated OpenGraph title. |
description |
string |
Updated OpenGraph description. |
image |
string |
Updated preview image identifier or asset URL. |
tags |
string[] |
Replacement list of classification tags. |
password |
string |
New plaintext password, or empty string "" to remove password gating. |
expiration |
integer |
New Unix timestamp in seconds, or null to remove expiration. |
apple |
string |
Updated iOS redirect URL. |
google |
string |
Updated Android redirect URL. |
geo |
record |
Updated regional country routing map. |
cloaking |
boolean |
Enable or disable edge link cloaking. |
redirectWithQuery |
boolean |
Enable or disable query parameter pass-through. |
autoLinkKey |
string |
Updated auto-linking identifier. |
unsafe |
boolean |
Administrative override for destination security scanning. |
comment |
string |
Updated operational notes. |
Request Example
curl -X PATCH "https://shaf.app/api/v1/links/summer-promo" \
-H "Authorization: Bearer $SHAF_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/checkout-v2",
"title": "Summer Sale 2026 - Extended"
}'Response Example (HTTP 200 OK)
{
"code": 0,
"data": {
"id": "lnk_39dfa01e8b",
"slug": "summer-promo",
"url": "https://example.com/checkout-v2",
"title": "Summer Sale 2026 - Extended",
"updatedAt": 1774183600
}
}5. Delete a Short Link
Permanently purge a short link and immediately invalidate its edge KV cache entry.
DELETE /api/v1/links/:slug
Query Parameters
domain(string, optional): Scopes deletion to a specific custom domain.
Response Example (HTTP 200 OK)
{
"code": 0,
"data": {
"deleted": true,
"slug": "summer-promo"
}
}Error Response Matrix
| Status | Code | Constant | Meaning & Mitigation |
|---|---|---|---|
400 |
40001 |
INVALID_URL |
Destination URL is malformed or lacks HTTP/HTTPS protocol. |
400 |
40002 |
INVALID_SLUG |
Slug contains illegal characters. Allowed: a-z, 0-9, -, _. |
400 |
40003 |
RESERVED_SLUG |
Slug collides with a protected system route (/api, /dashboard, etc.). |
401 |
40101 |
UNAUTHORIZED |
Bearer token is missing, expired, or invalid. |
403 |
40301 |
FORBIDDEN |
API key lacks links:write scope. |
403 |
40302 |
QUOTA_EXCEEDED |
Workspace has reached its active link capacity. Upgrade plan or archive links. |
403 |
40303 |
MALICIOUS_URL |
Target domain flagged as malware/phishing by Google Safe Browsing. |
404 |
40401 |
LINK_NOT_FOUND |
No link exists for the given slug and domain combination. |
409 |
40901 |
SLUG_EXISTS |
Slug is already registered under this custom domain. |
429 |
42901 |
RATE_LIMITED |
Exceeded rate limit quota. Inspect Retry-After header. |