REST API v1
Use an API key to create and manage short links from scripts, browser extensions, ShareX, or iOS Shortcuts. Every endpoint only operates on links owned by the key's account.
Authentication
First create an API key on the My links page. The plaintext key is shown only once.
Use either header:
Or:
Only a sha256 hash of the key is stored. Lost keys cannot be recovered; disable and create a new one. Each key allows up to 240 requests per hour.
Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /api/v1/links | Create a link (tags / groups / UTM supported) |
| GET | /api/v1/links | List your links with pagination; filter with ?tag=name&tag_kind=tag|group Filter |
| GET | /api/v1/links/{code} | Link details (with tags / groups) |
| PATCH | /api/v1/links/{code} | Update destination, note, expiry, password, click limit, status, tags / groups, UTM |
| DELETE | /api/v1/links/{code} | Soft delete (analytics retained) |
| GET | /api/v1/links/{code}/stats | Click analytics (7 days by default; ?days=1..30) |
Create a link
POST /api/v1/links,Content-Type: application/json。
Field reference:
| Field | Required | Description |
|---|---|---|
| url | Yes | Destination URL; http:// is added if missing; max 2000 characters |
| alias | No | Custom alias, 1–40 letters / numbers / underscores / hyphens; omitted means random |
| title | No | Note, up to 100 characters |
| expire_at | No | Expiry, e.g. 2026-12-31 23:59:59; omitted means permanent |
| password | No | Access password, 4–64 characters |
| max_clicks | No | Click limit; 0 or omitted means unlimited |
| tags | No | Tag array (or comma-separated string), each up to 30 characters; created automatically, max 8 |
| groups | No | Group array (or comma-separated string), same rules as tags; for campaign / project grouping |
| utm | No | Object; may contain source / medium / campaign / term / content (full keys such as utm_source are also accepted), each value up to 200 characters |
| utm_source etc. | No | May also be sent at the top level utm_source / utm_medium / utm_campaign / utm_term / utm_content |
On success, returns 201:
List and detail
The list returns items、total、page、per、pages; each item includes tags and groups arrays. A single-link request only returns links owned by the current account; another account's code always returns 404.
Update a link
PATCH /api/v1/links/{code}; send only the fields to change.
password An empty string clears the password;expire_at null makes the link permanent;max_clicks cannot be lower than clicks already recorded;tags / groups an empty array clears the binding;utm only appends or fills empty values; existing same-name parameters on the destination are not overwritten.
Delete and analytics
Analytics return total / today / unique visitors, daily series, top referrers, device breakdown,browsers、oses、countries and the latest 10 clicks (including browser、os、country); bots are excluded. An empty country means the request did not pass through Cloudflare or had no trusted country header.
Error codes
| HTTP | code | Meaning |
|---|---|---|
| 400 | invalid_json | Request body is not valid JSON |
| 401 | unauthorized / invalid_key | Missing or invalid API key |
| 403 | forbidden / account_disabled | Key lacks permission or the account is disabled |
| 404 | not_found | Link does not exist or belongs to another account |
| 409 | alias_taken / alias_invalid | Alias is taken or invalid |
| 422 | invalid_url / invalid_expire_at / invalid_password / invalid_max_clicks / unsafe_url | Validation failed or blocked by security |
| 429 | rate_limited / quota_exceeded | Rate limit exceeded or daily quota exhausted |
| 500 | server_error / create_failed | Server error |
All errors return {"ok":false,"error":{"code":"...","message":"..."}}。