URL Shortener API: A Getting-Started Guide
By Urlzee Team · Published · 5 min read
A URL shortener API lets your code create and manage short links without anyone opening a website. With Urlzee you send JSON over HTTPS to https://urlzee.com/api/v1, authenticate with a Bearer token, and get back the short URL. This guide goes from creating a key to reading click statistics, using curl throughout.
What do you need before making the first request?
An account and an API key. Both are free.
- Create a Urlzee account and open Dashboard → API keys.
- Create a key. It starts with
uz_live_and is shown once, so copy it immediately. - Store it in an environment variable rather than in your code:
export URLZEE_API_KEY="uz_live_YOUR_KEY"
The key identifies your account. Anyone who has it can create and delete your links, so keep it on a server and out of browser code, mobile apps and public repositories. API key security best practices covers storage and rotation.
How do you create a short link with the API?
Send a POST to /links with the destination in a JSON body:
curl -X POST https://urlzee.com/api/v1/links \
-H "Authorization: Bearer $URLZEE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/a/very/long/page"}'
A successful call returns 201 Created and the new link inside a data object:
{
"data": {
"id": "0b9f6c1e-5f0e-4a4b-9f38-2f1d1c0a7e11",
"slug": "k3Xp9Qa",
"short_url": "https://urlzee.com/k3Xp9Qa",
"destination": "https://example.com/a/very/long/page",
"title": null,
"clicks": 0,
"is_active": true,
"expires_at": null,
"created_at": "2026-11-30T09:15:00.000Z"
}
}
Keep the id. Every later operation on this link uses it, not the slug.
The request body accepts four fields:
| Field | Required | Notes |
|---|---|---|
url | Yes | Destination. Must be http or https and at most 2,048 characters. |
alias | No | Custom ending, 3 to 50 characters: letters, numbers, - and _. |
title | No | A label for your dashboard, up to 200 characters. |
expires_at | No | ISO 8601 date when the link stops working. Pro and Business only. |
Here is a link with a custom alias and a title:
curl -X POST https://urlzee.com/api/v1/links \
-H "Authorization: Bearer $URLZEE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/launch", "alias": "launch", "title": "Launch page"}'
If launch is free, the short URL is https://urlzee.com/launch. If someone already has it, you receive a 409 and should try another alias.
How do you list and fetch links?
GET /links returns your links, newest first, one page at a time:
curl "https://urlzee.com/api/v1/links?page=1&limit=25" \
-H "Authorization: Bearer $URLZEE_API_KEY"
limit can be anything from 1 to 100. The response contains a data array plus page, limit and total, so you know when to stop: keep requesting the next page until you have collected total links.
To fetch a single link, put its id in the path:
curl https://urlzee.com/api/v1/links/0b9f6c1e-5f0e-4a4b-9f38-2f1d1c0a7e11 \
-H "Authorization: Bearer $URLZEE_API_KEY"
An id that does not exist, or belongs to another account, returns 404.
How do you update, pause or delete a link?
PATCH /links/{id} accepts any combination of title, is_active, url and expires_at. Send only the fields you want to change.
Pause a link, on any plan:
curl -X PATCH https://urlzee.com/api/v1/links/0b9f6c1e-5f0e-4a4b-9f38-2f1d1c0a7e11 \
-H "Authorization: Bearer $URLZEE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"is_active": false}'
A paused link stops redirecting until you send {"is_active": true}.
Change where a link points, on Pro or Business:
curl -X PATCH https://urlzee.com/api/v1/links/0b9f6c1e-5f0e-4a4b-9f38-2f1d1c0a7e11 \
-H "Authorization: Bearer $URLZEE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/launch-v2"}'
The short URL stays the same and the next click goes to the new destination. On the free plan this request returns 403 with the code plan_required. The idea behind editable destinations is explained in dynamic links.
Delete a link:
curl -X DELETE https://urlzee.com/api/v1/links/0b9f6c1e-5f0e-4a4b-9f38-2f1d1c0a7e11 \
-H "Authorization: Bearer $URLZEE_API_KEY"
Deleting is permanent. The short URL stops working and its click history goes with it. If you might want the link back, pause it instead.
How do you read click statistics?
GET /links/{id}/stats returns clicks for a recent period, set with the days parameter:
curl "https://urlzee.com/api/v1/links/0b9f6c1e-5f0e-4a4b-9f38-2f1d1c0a7e11/stats?days=30" \
-H "Authorization: Bearer $URLZEE_API_KEY"
The response gives total clicks for the period, clicks per day, and the top countries, referrers, devices, browsers and operating systems. Bot traffic is reported separately in a bots field and is not included in the totals. The longest period you can request depends on your plan's analytics history, which is 30 days on Free and one year on Pro.
How should you handle errors?
Check the HTTP status first, then read the error body. Every error has the same shape:
{ "error": { "code": "alias_taken", "message": "That alias is already taken. Try another." } }
| Status | Code | What it means | What to do |
|---|---|---|---|
| 400 | bad_request | Body missing or not valid JSON | Fix the request body |
| 401 | unauthorized | Key missing, malformed or revoked | Check the Authorization header |
| 403 | plan_required | Feature needs a higher plan | Remove the field or upgrade |
| 404 | not_found | Link does not exist or is not yours | Check the id |
| 409 | alias_taken | Custom alias already in use | Choose another alias |
| 422 | url_*, alias_invalid | URL or alias failed validation, or the destination is blocked as unsafe | Correct the value named in the message |
| 429 | rate_limited | Too many requests, or monthly quota used up | Wait for Retry-After seconds |
Program against code, which is stable, and log message, which is written for people. A 422 on the URL is worth surfacing to your own users unchanged, because the message explains what was wrong. The meaning of each status in general is covered in the HTTP status codes guide.
What are the rate limits?
There are two limits: a per-minute rate and a monthly quota of requests. Creating links also draws on your plan's monthly link allowance.
| Plan | Requests per month | Requests per minute | Links per month |
|---|---|---|---|
| Free | 100 | 10 | 50 |
| Pro | 10,000 | 60 | 5,000 |
| Business | 100,000 | 300 | 50,000 |
Every response includes X-RateLimit-Limit and X-RateLimit-Remaining for the per-minute rate, and X-Quota-Limit and X-Quota-Remaining for the month. To see them, add -i to any curl command.
When you exceed a limit, the API returns 429 with a Retry-After header giving the number of seconds to wait. A client should read that header and pause, not retry immediately. API rate limiting explained shows a retry loop that does this properly.
Where to go from here
The same six endpoints are all there is: create, list, get, update, delete and stats. Language-specific walkthroughs are available for JavaScript and Node.js and for Python, and the API documentation is the reference for every field. Links made through the API go through the same safety checks as links made on the website and appear in the same dashboard.
Frequently asked questions
- Is there a free URL shortener API?
- Yes. Every Urlzee account, including free ones, can create an API key. The free plan allows 100 API requests and 50 new links per month; Pro allows 10,000 requests and Business 100,000.
- How do I authenticate with the Urlzee API?
- Send your key in the Authorization header as a Bearer token, for example 'Authorization: Bearer uz_live_YOUR_KEY'. Requests without a valid key receive a 401 response.
- Can I change a short link's destination through the API?
- Yes, with a PATCH request to /links/{id} that includes a new url. Changing the destination or expiry date requires the Pro or Business plan; changing the title or pausing a link works on every plan.
- Can I call a URL shortener API from browser JavaScript?
- You should not. Any key shipped in front-end code can be read by anyone who opens the page. Call the API from your own server and have your front end talk to that.