Skip to main content
Retrieve all short links created by the authenticated user.

Authentication

Authorization
string
required
Session-based authentication required. Endpoint returns 401 if not authenticated.

Response

Returns an array of link objects sorted by creation date (newest first).
id
number
Unique identifier for the link.
short_code
string
The short code used in the URL.
original_url
string
The destination URL.
created_at
string
ISO 8601 timestamp of when the link was created.
expires_at
string | null
ISO 8601 timestamp of when the link expires, or null if never expires.
custom_slug
boolean
Whether this link uses a custom slug (true) or auto-generated code (false).
clicks
number
Total number of times this link has been accessed.
user_id
string | null
The user ID who created this link.

Examples

curl -X GET https://shrtnr.app/api/links \
  -H "Cookie: session=your-session-token"

Success Response

200 OK
[
  {
    "id": 42,
    "short_code": "summer-sale",
    "original_url": "https://example.com/campaign/summer-sale",
    "created_at": "2026-03-01T10:30:00.000Z",
    "expires_at": "2026-03-31T10:30:00.000Z",
    "custom_slug": true,
    "clicks": 1337,
    "user_id": "user_abc123"
  },
  {
    "id": 41,
    "short_code": "Xy9pQz1m",
    "original_url": "https://example.com/article",
    "created_at": "2026-02-28T15:45:00.000Z",
    "expires_at": "2026-03-07T15:45:00.000Z",
    "custom_slug": false,
    "clicks": 42,
    "user_id": "user_abc123"
  }
]

Error Response

401 Unauthorized
{
  "error": "Unauthorized"
}

PATCH /api/links/[id]

Update an existing short link. Only the link owner can update their links.

Authentication

Authorization
string
required
Session-based authentication required.

Path Parameters

id
number
required
The unique identifier of the link to update. Must be a positive integer.

Request Body

shortCode
string
New short code for the link.
expiresAt
string | null
New expiration date as ISO 8601 timestamp, or null to remove expiration.
Both fields are optional. You can update either field independently or both together.

Response

ok
boolean
Returns true on successful update.

Error Responses

Examples

curl -X PATCH https://shrtnr.app/api/links/42 \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your-session-token" \
  -d '{
    "shortCode": "new-slug"
  }'

Success Response

200 OK
{
  "ok": true
}

DELETE /api/links/[id]

Delete a short link. Only the link owner can delete their links.

Authentication

Authorization
string
required
Session-based authentication required.

Path Parameters

id
number
required
The unique identifier of the link to delete. Must be a positive integer.

Response

ok
boolean
Returns true on successful deletion.

Error Responses

Examples

curl -X DELETE https://shrtnr.app/api/links/42 \
  -H "Cookie: session=your-session-token"

Success Response

200 OK
{
  "ok": true
}
Deletion is permanent and cannot be undone. The short code becomes available for reuse.

Build docs developers (and LLMs) love