API 文件

使用 Lab-URL V1 API 將短網址功能整合到您的應用程式、自動化流程或第三方工具中。

REST APIJSONPro+API Playground →

快速開始

1. 取得 API Key

登入管理後台,在 API Key 頁面建立一組 Key。需要 Pro 以上方案。

2. 發送 API 請求

使用 API Key 認證,呼叫 V1 API 端點。

建立短網址bash
curl -X POST https://api.lab-url.com/api/v2/urls \
  -H "X-API-Key: lurl_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{"original_url": "https://example.com/very-long-page"}'
回應json
{
  "result": 1,
  "data": {
    "id": 5,
    "short_code": "aBcDeFgH",
    "original_url": "https://example.com/very-long-page",
    "title": null,
    "visits": 0,
    "created_at": "2026-03-30T10:00:00.000000Z"
  },
  "text": "建立成功"
}

認證方式

V1 API 使用 API Key 認證。每個請求都需要帶上 Key,支援兩種方式:

Header(推薦)

X-API-Key: lurl_your_key

Query Parameter

?api_key=lurl_your_key
API Key 請妥善保管,不要放在前端程式碼或公開 repository 中。

Base URL

環境URL
正式https://api.lab-url.com/api/v2

API 端點

POST/api/v2/urls建立短網址

Request Body

參數類型必填說明
original_urlstring必填Target URL (max 2048)
titlestringCustom title (max 255)
custom_codestringCustom code (3~50 chars)
範例bash
curl -X POST https://api.lab-url.com/api/v2/urls \
  -H "X-API-Key: lurl_your_key" \
  -H "Content-Type: application/json" \
  -d '{"original_url": "https://github.com", "title": "GitHub"}'
回應 201json
{
  "result": 1,
  "data": {
    "id": 5,
    "short_code": "aBcDeFgH",
    "original_url": "https://github.com",
    "title": "GitHub",
    "visits": 0,
    "is_active": 1,
    "created_at": "2026-03-30T10:00:00.000000Z"
  },
  "text": "建立成功"
}
GET/api/v2/urls列出短網址

Query Parameters

參數類型必填說明
per_pageintPer page (default 20, max 100)
pageintPage number
searchstringSearch code/URL/title
sortstringcreated_at | visits | title
dirstringasc | desc
GET/api/v2/urls/{id}查詢短網址
範例bash
curl https://api.lab-url.com/api/v2/urls/5 \
  -H "X-API-Key: lurl_your_key"
PUT/api/v2/urls/{id}Update

Request Body

參數類型必填說明
original_urlstringNew target URL
titlestringNew title
is_activebooleanEnable/disable
DELETE/api/v2/urls/{id}刪除短網址
回應json
{ "result": 1, "text": "已刪除" }
GET/api/v2/urls/{id}/stats查詢統計

Query Parameters

參數類型必填說明
daysintDays (default 30)
回應json
{
  "result": 1,
  "data": {
    "total_visits": 42,
    "period_visits": 30,
    "by_date": [
      { "date": "2026-03-28", "count": 15 },
      { "date": "2026-03-29", "count": 12 }
    ]
  }
}
GET/api/v2/urls/{id}/qrcodeQR Code

Query Parameters

參數類型必填說明
sizeint100~1000 (default 300)

Returns PNG image (Content-Type: image/png)

錯誤碼

HTTPCode說明
401INVALID_API_KEYInvalid or missing API Key
403QUOTA_EXCEEDEDMonthly quota exceeded
404NOT_FOUNDShort URL not found
422BLACKLISTEDDomain is blacklisted
422VALIDATION_ERRORValidation failed
429RATE_LIMITEDToo many requests

速率限制

PlanLimitAPI Keys
Pro1,000 / month1
BusinessUnlimited10

準備好開始了嗎?

升級到 Pro 方案即可取得 API Key,開始整合 Lab-URL API。