API 参考

基础 URL: https://open.utm.bar/v1
认证方式: Authorization: Bearer sk_live_xxxxX-API-Key: sk_live_xxxx


短链接

创建短链接

POST /v1/links

所需权限: links:write

请求体

字段类型必填说明
original_urlstring目标跳转 URL
titlestring链接展示名称
custom_codestring自定义短码(a-z A-Z 0-9 - _,长度 2–64)
external_idstring外部系统引用 ID,透传存储(最大 255 字符)
expires_atISO 8601过期时间,null 表示永不过期
utm_sourcestringUTM source 参数
utm_mediumstringUTM medium 参数
utm_campaignstringUTM campaign 参数
utm_termstringUTM term 参数
utm_contentstringUTM content 参数
curl -X POST https://open.utm.bar/v1/links \
  -H "Authorization: Bearer sk_live_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "original_url": "https://example.com/page",
    "title": "我的链接",
    "custom_code": "launch-2026",
    "utm_source": "twitter",
    "utm_medium": "social"
  }'

响应 201 Created

{
  "data": {
    "id": "...",
    "code": "launch-2026",
    "short_url": "https://utm.bar/launch-2026",
    "original_url": "https://example.com/page",
    "title": "我的链接",
    "is_active": true,
    "click_count": 0,
    "external_id": "order_98765",
    "expires_at": null,
    "utm_source": "twitter",
    "utm_medium": "social",
    "created_at": "2026-05-25T00:00:00Z"
  }
}

自定义短码冲突时返回 409 Conflict


列出短链接

GET /v1/links

所需权限: links:read

查询参数

参数类型默认值说明
pageinteger1页码
page_sizeinteger20每页条数(最大 100)
qstring按标题或目标 URL 搜索
is_activeboolean按启用/禁用状态过滤
curl "https://open.utm.bar/v1/links?page=1&page_size=20" \
  -H "Authorization: Bearer sk_live_xxxx"

响应 200 OK

{
  "data": {
    "items": [ /* 链接对象数组 */ ],
    "total": 42,
    "page": 1,
    "page_size": 20
  }
}

获取单条链接

GET /v1/links/:code

所需权限: links:read

curl https://open.utm.bar/v1/links/launch-2026 \
  -H "Authorization: Bearer sk_live_xxxx"

响应 200 OK — 返回单个链接对象。


按 External ID 获取链接

GET /v1/links/external/:external_id

所需权限: links:read

根据创建时传入的 external_id 反向查找短链接,语义与按短码查找对称。未找到返回 404。

curl https://open.utm.bar/v1/links/external/order_98765 \
  -H "Authorization: Bearer sk_live_xxxx"

响应 200 OK

{
  "data": {
    "id": "...",
    "code": "launch-2026",
    "short_url": "https://utm.bar/launch-2026",
    "original_url": "https://example.com/page",
    "external_id": "order_98765",
    "is_active": true,
    "click_count": 42,
    "created_at": "2026-05-25T00:00:00Z"
  }
}

更新链接元数据

PATCH /v1/links/:code

所需权限: links:write

original_urlcode 创建后不可修改。如需更换目标地址,请创建新链接并停用旧的。

请求体(所有字段可选)

字段类型说明
titlestring新标题
expires_atISO 8601 / null更新或清除过期时间
utm_sourcestring更新 UTM source
utm_mediumstring更新 UTM medium
utm_campaignstring更新 UTM campaign
utm_termstring更新 UTM term
utm_contentstring更新 UTM content
curl -X PATCH https://open.utm.bar/v1/links/launch-2026 \
  -H "Authorization: Bearer sk_live_xxxx" \
  -H "Content-Type: application/json" \
  -d '{ "title": "新标题", "expires_at": "2026-12-31T23:59:59Z" }'

响应 200 OK — 返回更新后的链接对象。


禁用链接

POST /v1/links/:code/disable

所需权限: links:delete

curl -X POST https://open.utm.bar/v1/links/launch-2026/disable \
  -H "Authorization: Bearer sk_live_xxxx"

响应 200 OK


启用链接

POST /v1/links/:code/enable

所需权限: links:write

curl -X POST https://open.utm.bar/v1/links/launch-2026/enable \
  -H "Authorization: Bearer sk_live_xxxx"

响应 200 OK


删除链接

DELETE /v1/links/:code

所需权限: links:delete

删除操作不可撤销。如果日后可能还需要这个链接,建议改用禁用操作。

curl -X DELETE https://open.utm.bar/v1/links/launch-2026 \
  -H "Authorization: Bearer sk_live_xxxx"

响应 204 No Content


获取点击统计

GET /v1/links/:code/stats

所需权限: links:read

查询参数

参数类型默认值说明
startYYYY-MM-DD近 7 天起始日期(含)
endYYYY-MM-DD今天截止日期(含)
tzIANA 时区名UTC用于按时区聚合日期边界
curl "https://open.utm.bar/v1/links/launch-2026/stats?start=2026-05-01&end=2026-05-25&tz=Asia/Shanghai" \
  -H "Authorization: Bearer sk_live_xxxx"

响应 200 OK

{
  "data": {
    "total_clicks": 1024,
    "unique_clicks": 876,
    "tz": "Asia/Shanghai",
    "daily": [
      { "date": "2026-05-01", "clicks": 40, "unique_clicks": 35 },
      { "date": "2026-05-02", "clicks": 55, "unique_clicks": 48 }
    ]
  }
}

频率限制

限流以团队为粒度,同一团队下所有 API Key 共享配额。

请求类型限制
写操作(创建 / 更新 / 禁用 / 删除)60 次 / 分钟
读操作(列表 / 详情 / 统计)300 次 / 分钟

超限时返回 429 Too Many Requests,响应头包含:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1748140860
Retry-After: 30

权限范围

Scope授权操作
links:read列表查询、获取详情、获取统计
links:write创建链接、更新元数据、启用链接
links:delete禁用链接、删除链接

错误响应

所有错误使用统一的结构:

{
  "error": "error_code",
  "message": "人类可读的错误描述",
  "request_id": "req_abc123"
}
状态码error含义
400invalid_request参数校验失败
401unauthorizedKey 缺失或无效
403forbiddenKey 缺少所需权限
404not_found资源不存在
409conflict自定义短码已被占用
429rate_limited超出频率限制
500internal_error服务端错误