API 文件
使用 ZIPN API 以程式設計方式縮短 URL。
概述
訪客每24小時可免費建立最多3個連結。
- Base URL:
https://zipn.app/api/v1/shorten - 格式: JSON
- 認證: 選填(無金鑰時為臨時連結,使用 API 金鑰時為個人代碼連結)
驗證(API 金鑰)
登入後在個人資料中建立 API 金鑰,並放在請求標頭中傳送。連結將在你的個人代碼下建立且不會過期,你可以在儀表板中編輯並查看統計。
Authorization: Bearer sk_short_...- 金鑰僅在建立時顯示一次。如果遺失,請撤銷並重新建立。
- 每個帳戶最多 5 個金鑰,每個金鑰每分鐘 30 次、每天 1,000 次請求。超出時回傳 429 及 Retry-After 標頭。
- 如果金鑰錯誤或已撤銷,將回傳 401,而不會改為建立臨時連結。
縮短網址
POST /api/v1/shorten
請求參數:
| 參數 | 必填 | 描述 |
|---|---|---|
original_url | ✅ | 要縮短的原始網址 |
custom_code | ❌ | 自訂短代碼(如果省略則會自動產生) |
expire_duration | ❌ | 有效期限:24h, 48h, 1week, 1month |
code_id | ❌ | 使用 API 金鑰時:要使用的個人代碼 ID(預設為主要代碼)。傳入 temp 會建立臨時連結,並在儀表板中管理。 |
請求範例:
curl -X POST https://zipn.app/api/v1/shorten \
-H "Content-Type: application/json" \
-d '{
"original_url": "https://example.com/very-long-url",
"custom_code": "example",
"expire_duration": "1week"
}'成功響應(201):
{
"status": "success",
"message": "URL shortened successfully.",
"data": {
"short_url": "https://zipn.app/example/",
"original_url": "https://example.com/very-long-url",
"code": "example",
"expiration_date": "2026-04-21T10:00:00.000Z"
}
}使用 API 金鑰請求:
curl -X POST https://zipn.app/api/v1/shorten \
-H "Authorization: Bearer sk_short_..." \
-H "Content-Type: application/json" \
-d '{
"original_url": "https://example.com/very-long-url",
"custom_code": "example"
}'使用 API 金鑰的成功回應 (201):
{
"status": "success",
"message": "URL shortened successfully.",
"data": {
"short_url": "https://zipn.app/mycode/example/",
"original_url": "https://example.com/very-long-url",
"code": "example",
"expiration_date": "2126-03-28T10:00:00.000Z",
"username": "mycode",
"user_code_id": 12,
"is_temp": false
}
}錯誤回應:
{
"status": "error",
"message": "This short code is already in use."
}取得API資訊
GET /api/v1/shorten
返回端點資訊和可用參數。