Create Link
Added in v1.0
POST
https://api.example.com/api/linkRequires authentication: x-api-key: YOUR_API_KEY
Creates a new shortened link. The link name and destination URL must be supplied in the request body. The link is attributed to API as its creator.
Headers
x-api-keystringrequiredYour API authentication key.Content-TypestringrequiredMust beapplication/json.
Body parameters
namestringrequiredThe unique name to assign to the shortened link. Maximum 100 characters.urlstringrequiredThe destination URL. Must start withhttp://orhttps://.
Tip
The following names are reserved and cannot be used: api, auth, staff, settings, user, users, login, logout, uploads, css, js, logo, links, 403 (case-insensitive).
Responses
- 201Created
- 400Bad Request
- 409Conflict
Request
curl -X POST 'https://api.example.com/api/link' \
-H 'x-api-key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"name": "google",
"url": "https://google.com"
}'
const res = await fetch('https://api.example.com/api/link', {
method: 'POST',
headers: {
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: 'google', url: 'https://google.com' })
});
const link = await res.json();
import requests
res = requests.post(
'https://api.example.com/api/link',
headers={'x-api-key': 'YOUR_API_KEY'},
json={'name': 'google', 'url': 'https://google.com'}
)
link = res.json()
$ch = curl_init('https://api.example.com/api/link');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'x-api-key: YOUR_API_KEY',
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'name' => 'google',
'url' => 'https://google.com'
]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$link = json_decode(curl_exec($ch), true);
201 Created
{
"id": 1,
"name": "google",
"url": "https://google.com",
"count": 0,
"creator": "API",
"creatorID": "0",
"createdAt": 1795400000000
}
400 Bad Request
{
"msg": "Enter a name and URL."
}
Other possible msg values:
Name must be 100 characters or less.The destination must start with http:// or https://.That name is reserved.
409 Conflict
{
"msg": "A link with that name already exists."
}
Discussion 0
Reading is open to everyone. Posting, replying, reacting and reporting require a Discord account — we only receive your public username and avatar.
No comments yet. Sign in with Discord to start the conversation.
Sign in required
Reading is open to everyone. Posting, replying, reacting and reporting require a Discord account — we only receive your public username and avatar.