快速開始
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_keyQuery Parameter
?api_key=lurl_your_keyAPI Key 請妥善保管,不要放在前端程式碼或公開 repository 中。
Base URL
| 環境 | URL |
|---|---|
| 正式 | https://api.lab-url.com/api/v2 |
API 端點
POST
/api/v2/urls建立短網址Request Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| original_url | string | 必填 | Target URL (max 2048) |
| title | string | 否 | Custom title (max 255) |
| custom_code | string | 否 | Custom 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_page | int | 否 | Per page (default 20, max 100) |
| page | int | 否 | Page number |
| search | string | 否 | Search code/URL/title |
| sort | string | 否 | created_at | visits | title |
| dir | string | 否 | asc | 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}UpdateRequest Body
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| original_url | string | 否 | New target URL |
| title | string | 否 | New title |
| is_active | boolean | 否 | Enable/disable |
DELETE
/api/v2/urls/{id}刪除短網址回應json
{ "result": 1, "text": "已刪除" }GET
/api/v2/urls/{id}/stats查詢統計Query Parameters
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| days | int | 否 | Days (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 CodeQuery Parameters
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
| size | int | 否 | 100~1000 (default 300) |
Returns PNG image (Content-Type: image/png)
錯誤碼
| HTTP | Code | 說明 |
|---|---|---|
| 401 | INVALID_API_KEY | Invalid or missing API Key |
| 403 | QUOTA_EXCEEDED | Monthly quota exceeded |
| 404 | NOT_FOUND | Short URL not found |
| 422 | BLACKLISTED | Domain is blacklisted |
| 422 | VALIDATION_ERROR | Validation failed |
| 429 | RATE_LIMITED | Too many requests |
速率限制
| Plan | Limit | API Keys |
|---|---|---|
| Pro | 1,000 / month | 1 |
| Business | Unlimited | 10 |
準備好開始了嗎?
升級到 Pro 方案即可取得 API Key,開始整合 Lab-URL API。