Shorten Magic API
Create short links from your own code with a single JSON request.
Public API access is currently closed. Requests to the endpoint return 403 for now. Contact us if you'd like access for your project.
Overview
The API has one endpoint. Send the long URL as JSON (or as a normal form post) and you get the short link back. Links created through the API are public, just like links created on the home page.
https://www.shortenmagic.com/api/shortenCreate a link
| Field | Type | Description |
|---|---|---|
| url | string | Required. The destination URL. If you leave out the scheme, https:// is added. |
| alias | string | Optional custom ending, 3–30 characters: letters, numbers, - and _. |
If the same URL was already shortened without a custom alias, the API returns the existing short link instead of creating a new one.
Responses
New links are reviewed before they start redirecting, so a new link returns 202 with "pending": true. If the same URL is already live, you get the existing link back with 200. The body looks like this:
{
"ok": true,
"pending": true,
"short_url": "https://www.shortenmagic.com/fallsale",
"code": "fallsale",
"url": "https://examplestore.com/campaign",
"message": "Your link was received and will start working after a quick review."
}Errors
Errors return {"ok": false, "error": "…"} with a message you can show to your users.
| Code | Meaning |
|---|---|
| 400 | The URL is invalid, or the alias is invalid or already taken. |
| 405 | The request wasn't a POST. |
| 429 | Too many links from your IP address in the last hour. |
| 500 | Something went wrong on our side. Try again in a moment. |
Rate limits
Each IP address can create up to 30 links per hour. Need more for a real project? Tell us about it.
cURL
curl -X POST https://www.shortenmagic.com/api/shorten \
-H "Content-Type: application/json" \
-d '{"url":"https://examplestore.com/campaign","alias":"fallsale"}'PHP
$ch = curl_init('https://www.shortenmagic.com/api/shorten');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode(['url' => 'https://examplestore.com/campaign']),
]);
$res = json_decode(curl_exec($ch), true);
echo $res['short_url'] ?? $res['error'];JavaScript
const res = await fetch('https://www.shortenmagic.com/api/shorten', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ url: 'https://examplestore.com/campaign' })
});
const data = await res.json();
console.log(data.short_url);