API 文件
所有功能都能用 HTTP 呼叫。回傳皆為 JSON,支援 CORS,可以直接在瀏覽器或任何程式語言使用。
Base URL
https://xn--jj0a.tw/apiPOST /api/create
建立一個短網址。成功回傳 201 與 manage_key(管理金鑰只會出現這一次,請妥善保存)。
curl -X POST https://xn--jj0a.tw/api/create \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/very/long/link","slug":"貓","max_clicks":100}'const res = await fetch("https://xn--jj0a.tw/api/create", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ url: "https://example.com", gen: { charset: "emoji", length: 2 } })
});
const { link } = await res.json();
console.log(link.short_url, link.manage_key);參數
| 欄位 | 型別 | 說明 |
|---|---|---|
url | string | 必填。要縮短的網址,沒寫協定會自動補 https:// |
slug | string | 自訂短碼,支援中文、Emoji、- _ .;留空自動產生 |
gen | object | 自動短碼規則 {"charset":"alnum","length":5},charset 可用 alnum / lower / digits / readable / pronounce / hanzi / emoji / zhuyin |
title | string | 備註,只有管理者看得到 |
password | string | 存取密碼 |
redirect_type | string | 302(預設)/ 301 / 307 / 308 / splash 中繼頁 / meta 隱藏來源 |
splash_seconds | int | 中繼頁倒數秒數 0–60,0 代表手動點擊 |
splash_message | string | 中繼頁顯示的訊息 |
starts_at | int|string | 開始生效時間(Unix 秒或 ISO 8601) |
expires_at | int|string | 到期時間(Unix 秒或 ISO 8601) |
ttl | int | 幾秒後到期(會覆蓋 expires_at),例:86400 |
max_clicks | int | 點擊上限,1 = 閱後即焚 |
fallback_url | string | 到期或額滿後改導向的網址 |
forward_query | bool | 把短網址後面的 ?參數 傳給目的地 |
public_stats | bool | 公開統計頁 |
rules | object | 智慧分流,見下方範例 |
og | object | 社群預覽卡 {"title":"","desc":"","image":""} |
webhook | object | 點擊通知 {"url":"https://…","format":"json|discord|slack"} |
回應
{
"ok": true,
"link": {
"slug": "貓",
"short_url": "https://縮.tw/貓",
"short_url_ascii": "https://xn--jj0a.tw/%E8%B2%93",
"status": "active",
"manage_key": "a7Kx…",
"manage_url": "https://xn--jj0a.tw/stats/%E8%B2%93#key=a7Kx…",
…
}
} 錯誤時回傳 {"ok":false,"error":"說明","field":"欄位"} 與對應的 HTTP 狀態碼(422 / 409 / 429…)。持有 API 金鑰時可在標頭帶上 X-Api-Key 取得較高的速率限制。
POST /api/bulk
一次建立最多 100 個短網址;options 會套用到每一筆。每行可用「網址 空白 短碼」指定短碼。
{
"urls": ["https://a.example", "https://b.example 自訂短碼"],
"options": { "expires_at": "2026-12-31T23:59:59+08:00", "gen": { "charset": "readable", "length": 6 } }
}管理(需要 X-Manage-Key 標頭)
GET
/api/link?slug=貓取得完整設定POST
/api/update修改設定,body 帶 slug 與要改的欄位;改短碼用 new_slug;移除密碼用 remove_password: truePOST
/api/toggle停用 / 啟用 {"slug":"貓","disabled":true}POST
/api/reset統計歸零POST
/api/delete永久刪除GET
/api/export?slug=貓下載點擊紀錄 CSVPOST
/api/webhook-test送出一則測試 Webhookcurl -X POST https://xn--jj0a.tw/api/update \
-H "Content-Type: application/json" \
-H "X-Manage-Key: 你的管理金鑰" \
-d '{"slug":"貓","url":"https://new.example","ttl":3600}'公開工具
GET
/api/check?slug=貓短碼是否可用GET
/api/random?charset=hanzi&length=2產生一個未被使用的隨機短碼GET
/api/site全站統計數字GET /api/stats?slug=貓&range=7d
range:24h / 7d / 30d / 90d / all;tz:JavaScript 的 getTimezoneOffset()(台灣為 -480)。公開統計的連結不需金鑰,否則請帶 X-Manage-Key。
{
"ok": true,
"totals": { "clicks": 128, "uniques": 97, "today": 12, "bots": 31, "all_time": 860 },
"series": [ { "t": 1761580800, "v": 18 }, … ],
"heat": [[0,0,…], …], // 7 × 24,週日起算
"breakdown": { "referrer": [ { "k": "facebook.com", "v": 52 } ], "device": […], … },
"recent": [ { "ts": 1761650000, "country": "TW", "device": "mobile", … } ]
}分流規則 rules
判斷順序為 時段 → 裝置 → 國家 → 語言 → 輪播 → 主網址,第一個符合的規則勝出。國家判斷需要網站經過 Cloudflare 代理(CF-IPCountry)。
{
"time": [ { "days": [1,2,3,4,5], "from": "09:00", "to": "18:00", "url": "https://office.example" } ],
"device": { "ios": "https://apps.apple.com/…", "android": "https://play.google.com/…", "mobile": "", "desktop": "" },
"geo": [ { "c": "JP,KR", "url": "https://asia.example" } ],
"lang": [ { "l": "en", "url": "https://example.com/en" } ],
"rotate": { "mode": "random", "w0": 1, "items": [ { "url": "https://b.example", "w": 1 } ] }
}Webhook 格式
每次真人點擊後,伺服器會在回應送出後 POST 到你的網址(逾時 5 秒、不重試)。format 為 discord 或 slack 時會送出對應的訊息格式;json 則是:
{
"event": "click", "slug": "貓", "short_url": "https://縮.tw/貓",
"destination": "https://example.com", "target": "main", "clicks": 42,
"time": "2026-10-30T12:00:00+08:00", "country": "TW", "lang": "zh-TW",
"device": "mobile", "os": "iOS", "browser": "LINE", "referrer": "facebook.com"
}書籤小工具
把下面的按鈕拖曳到瀏覽器的書籤列。之後在任何網頁點一下,就會帶著目前網址跳到 縮.tw 準備縮短。
縮一下 也可以直接分享 https://xn--jj0a.tw/?url=網址,打開時會自動帶入。