URL Shortener API Documentation
URL Shortener has a simple REST API for creating and managing short links. Anyone can create a basic short link without an account — sign up for free to unlock custom aliases, passwords, expiry dates and full management of your links.
Quickstart
Shorten a link with one request, no account or API key required:
curl -X POST https://yrl.sh/api/v2/links \
-H "Content-Type: application/json" \
-d '{"target": "https://example.com/a-very-long-url"}'
Same thing from JavaScript:
const res = await fetch("https://yrl.sh/api/v2/links", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ target: "https://example.com/a-very-long-url" }),
});
const link = await res.json();
console.log(link.link); // https://yrl.sh/xY7pQ2
Base URL
https://yrl.sh/api
/api/v2 also works and is equivalent — use whichever you prefer.
Authentication
You don't need an API key to shorten a basic link. To manage links tied to your account (custom alias, password-protected links, editing, deleting), generate an API key from your Settings page and send it on every request as a header:
X-API-KEY: your-api-key-here
Guest (not logged in) links instead return a one-time secret in
the creation response. Keep it — it's the only way to edit, view stats
for, or delete that link later, since there's no account tied to it. There's
no way to recover a lost guest secret, so save it immediately.
POST /api/v2/links
Create a new short link.
Body (JSON)
| Field | Required | Description |
|---|---|---|
target | Yes | The long URL to shorten. |
customurl | Account only | A custom alias instead of a random one. |
password | Account only | Require a password before redirecting. |
expire_in | No | Relative expiry, e.g. "1 day", "2 weeks". |
description | No | A note shown in your link list. |
Response 201 Created
{
"id": "abc123",
"address": "xY7pQ2",
"link": "https://yrl.sh/xY7pQ2",
"target": "https://example.com/a-very-long-url",
"secret": "only returned once, for guest links"
}
GET /api/v2/links
List your account's links. Requires X-API-KEY or a logged-in session — there's no listing endpoint for guest links, since they aren't tied to an account.
Query parameters
| Param | Default | Description |
|---|---|---|
limit | 10 | Results per page, max 50. |
skip | 0 | Results to skip, for pagination. |
search | — | Filter by target URL or description. |
curl https://yrl.sh/api/v2/links?limit=20&skip=0 \
-H "X-API-KEY: your-api-key-here"
GET /api/v2/links/:id/stats
Get click analytics for a link: total visits, referrers, countries, browsers and OS, broken down by day.
Owners pass X-API-KEY; guests pass their link's secret as
?secret=....
curl https://yrl.sh/api/v2/links/abc123/stats?secret=YOUR_SECRET
PATCH /api/v2/links/:id
Update a link. Guests may change description and expire_in only;
custom alias and password require an account. Owners pass X-API-KEY;
guests pass {"secret": "YOUR_SECRET"} in the body alongside the fields to change.
curl -X PATCH https://yrl.sh/api/v2/links/abc123 \
-H "Content-Type: application/json" \
-d '{"secret": "YOUR_SECRET", "description": "updated note"}'
DELETE /api/v2/links/:id
Delete a link. Owners pass X-API-KEY; guests pass
?secret=YOUR_SECRET. Deletion is immediate and can't be undone.
curl -X DELETE "https://yrl.sh/api/v2/links/abc123?secret=YOUR_SECRET"
Status codes
| Code | Meaning |
|---|---|
| 200 | OK — request succeeded. |
| 201 | Created — link created successfully. |
| 400 | Bad request — missing or invalid field, see the error message. |
| 401 | Unauthorized — missing/invalid API key or secret. |
| 404 | Not found — the link doesn't exist or was deleted. |
| 429 | Too many requests — you're being rate limited, slow down. |
Errors
Errors are returned as JSON with a matching HTTP status and a human-readable message:
{ "error": "Link not found." }
Rate limits & fair use
The API is free to use for normal traffic. We may throttle or block API keys and IPs that send abusive or excessive volume. If you need higher limits for a legitimate use case, reach out — see the contact link in the footer.
Need help?
Questions about the API or something not covered here? See the Terms of Service or use the contact link in the footer.