REST API v1
用 API Key 在脚本、浏览器插件、ShareX、iOS 快捷指令里创建和管理短链。所有接口只操作当前 Key 所属账号的链接。
认证
先在 我的链接 页面创建 API Key,明文只显示一次。
请求时二选一:
Authorization: Bearer tr_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
或:
X-API-Key: tr_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Key 只存 sha256,遗失后无法找回,只能停用后重新创建。每个 Key 每小时最多 240 次请求。
接口一览
| 方法 | 路径 | 说明 |
|---|---|---|
| POST | /api/v1/links | 创建短链(支持标签/分组/UTM) |
| GET | /api/v1/links | 分页列出自己的短链;可用 ?tag=名称&tag_kind=tag|group 筛选 |
| GET | /api/v1/links/{code} | 单条详情(含标签/分组) |
| PATCH | /api/v1/links/{code} | 修改目标、备注、有效期、密码、点击上限、启停、标签/分组、UTM |
| DELETE | /api/v1/links/{code} | 软删除(统计保留) |
| GET | /api/v1/links/{code}/stats | 点击统计(默认 7 天,可用 ?days=1..30) |
创建短链
POST /api/v1/links,Content-Type: application/json。
curl -X POST "https://taourl.de/api/v1/links" \
-H "Authorization: Bearer tr_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/a/very/long/path",
"alias": "promo2026",
"title": "秋季活动",
"expire_at": "2026-12-31 23:59:59",
"password": "1234",
"max_clicks": 500,
"tags": ["双十一", "微信"],
"groups": ["2026 秋季活动"],
"utm": {
"source": "wechat",
"medium": "social",
"campaign": "autumn"
}
}'
字段说明:
| 字段 | 必填 | 说明 |
|---|---|---|
| url | 是 | 长链接,自动补 http://,上限 2000 字符 |
| alias | 否 | 自定义后缀,1–40 位字母/数字/下划线/短横线;不传则随机生成 |
| title | 否 | 备注,最长 100 字 |
| expire_at | 否 | 有效期,如 2026-12-31 23:59:59;不传为永久 |
| password | 否 | 访问密码,4–64 位 |
| max_clicks | 否 | 点击上限,0 或省略表示不限 |
| tags | 否 | 标签数组(或逗号分隔字符串),每个最长 30 字;自动创建,最多 8 个 |
| groups | 否 | 分组数组(或逗号分隔字符串),规则同标签;用于活动/项目归类 |
| utm | 否 | 对象,可含 source / medium / campaign / term / content(也接受 utm_source 等完整键),值最长 200 字 |
| utm_source 等 | 否 | 也可直接放顶层 utm_source / utm_medium / utm_campaign / utm_term / utm_content |
成功返回 201:
{
"ok": true,
"data": {
"code": "promo2026",
"short_url": "https://taourl.de/promo2026",
"url": "https://example.com/a/very/long/path?utm_source=wechat&utm_medium=social&utm_campaign=autumn",
"alias": "promo2026",
"title": "秋季活动",
"tags": ["双十一", "微信"],
"groups": ["2026 秋季活动"],
"status": 1,
"state": "live",
"click_count": 0,
"max_clicks": 500,
"clicks_left": 500,
"has_password": true,
"expire_at": "2026-12-31 23:59:59",
"created_at": "2026-11-26 12:00:00",
"last_click_at": null,
"safety_status": 0,
"safety_label": "未检测"
}
}
列表与详情
# 列表:?page=1&per=20&status=live|disabled
curl "https://taourl.de/api/v1/links?page=1&per=20" \
-H "Authorization: Bearer tr_live_xxx"
# 按标签/分组筛选(名称精确匹配)
curl "https://taourl.de/api/v1/links?tag=%E5%8F%8C%E5%8D%81%E4%B8%80&tag_kind=tag" \
-H "Authorization: Bearer tr_live_xxx"
# 单条
curl "https://taourl.de/api/v1/links/promo2026" \
-H "Authorization: Bearer tr_live_xxx"
列表返回 items、total、page、per、pages;每条 item 含 tags 与 groups 数组。单条只返回当前账号自己的链接,别人的 code 一律 404。
修改短链
PATCH /api/v1/links/{code},只传需要改的字段。
curl -X PATCH "https://taourl.de/api/v1/links/promo2026" \
-H "Authorization: Bearer tr_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"title": "活动已结束",
"status": 0,
"max_clicks": 0,
"password": "",
"tags": ["已归档"],
"groups": [],
"utm": {"campaign": "autumn-closed"}
}'
password 传空字符串表示清除密码;expire_at 传 null 表示改为永久;max_clicks 不能低于已经产生的点击数;tags / groups 传空数组表示清空绑定;utm 只追加/补空,不覆盖目标 URL 已有的同名参数。
删除与统计
# 删除
curl -X DELETE "https://taourl.de/api/v1/links/promo2026" \
-H "Authorization: Bearer tr_live_xxx"
# 统计(默认 7 天)
curl "https://taourl.de/api/v1/links/promo2026/stats?days=7" \
-H "Authorization: Bearer tr_live_xxx"
统计返回累计/今日/独立访客、每日序列、来源 Top、设备分布、browsers、oses、countries 和最近 10 条点击(含 browser、os、country);已排除爬虫。国家字段为空表示请求未经过 Cloudflare 或没有可信国家头。
错误码
| HTTP | code | 含义 |
|---|---|---|
| 400 | invalid_json | 请求体不是合法 JSON |
| 401 | unauthorized / invalid_key | 缺少或无效的 API Key |
| 403 | forbidden / account_disabled | Key 权限不足或账号被停用 |
| 404 | not_found | 链接不存在或不属于当前账号 |
| 409 | alias_taken / alias_invalid | 后缀被占用或不合规 |
| 422 | invalid_url / invalid_expire_at / invalid_password / invalid_max_clicks / unsafe_url | 参数校验失败或被安全服务拦截 |
| 429 | rate_limited / quota_exceeded | 请求超频或当日额度用完 |
| 500 | server_error / create_failed | 服务端错误 |
错误统一返回 {"ok":false,"error":{"code":"...","message":"..."}}。