Skip to content

Help article

Automate with the link-shortening API

Call the yhor API at api.yhor.xyz to shorten links automatically from a CMS, bot, or internal tool.

By yhor.xyz·
1

API base and Swagger reference

The API server lives at https://api.yhor.xyz and returns JSON for every endpoint. Interactive specs are at https://api.yhor.xyz/swagger, where you can fire test requests directly from the browser. The spec covers both auth and link management with copy-ready payload samples.

2

Create links without logging in

POST /api/links accepts anonymous calls. Send JSON with at least `url`, plus optional `customAlias` or an ISO-8601 `expiresAt`. A working curl: `curl -X POST https://api.yhor.xyz/api/links -H "Content-Type: application/json" -d '{"url":"https://example.com/article","customAlias":"promo"}'`. The response includes a `shortUrl` ready to use.

3

JavaScript fetch example

Hit the same endpoint from a browser or Node app with fetch: `const res = await fetch("https://api.yhor.xyz/api/links", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ url: "https://example.com", expiresAt: "2026-12-31T23:59:59+07:00" }) }); const { shortUrl } = await res.json();`. The same shape works inside an Edge Function or Cloudflare Worker since it's standard fetch.

4

Log in with JWT to manage your links

/auth/register and /auth/login return a 15-minute access token plus a 7-day refresh token. Pass the access token as `Authorization: Bearer <token>` to call GET /api/links/me?page=&limit=, PUT /api/links/:shortId, DELETE /api/links/:shortId, or GET /api/links/:shortId/stats. When it expires, call /auth/refresh to rotate; the server revokes the whole chain if a reused token is detected.

5

Anonymous rate limit

Callers without a token are capped at 30 POST /api/links requests per hour per IP. The counter is backed by Redis and resets each hour. If your integration needs more, register an account and use JWT to remove the cap. Always handle a 429 response by backing off before retrying.

6

Common integration patterns

Wire it into a CMS so every article gets a tidy share URL on publish. Drop it into a LINE or Discord bot to compress long URLs before replying. Use it in internal tools to mint campaign links with a memorable `customAlias`, then pull click data from /api/links/:shortId/stats to render in your own dashboards.