Code examples for creating a link
Prerequisites
- A Rebrandly account with an API key. Generate one in Settings > API keys.
Create a link
The examples below create a branded short link using POST /v1/links. Each example omits domain (so Rebrandly uses your account's default domain) and omits slashtag (so Rebrandly generates one randomly).
Replace YOUR_API_KEY with your API key. To use your own branded domain, see Branded domains.
curl -X POST \
https://api.rebrandly.com/v1/links \
-H 'apikey: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"destination": "https://www.brandyour.link",
"title": "My first branded link"
}'// Requires Node 18+
async function main() {
const response = await fetch('https://api.rebrandly.com/v1/links', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'apikey': 'YOUR_API_KEY'
},
body: JSON.stringify({
destination: 'https://www.brandyour.link',
title: 'My first branded link'
})
});
if (!response.ok) {
throw new Error(`API error: ${response.status}`);
}
const link = await response.json();
console.log(`Short URL: https://${link.shortUrl}`);
}
main().catch(console.error);import requests
response = requests.post(
'https://api.rebrandly.com/v1/links',
headers={
'Content-Type': 'application/json',
'apikey': 'YOUR_API_KEY'
},
json={
'destination': 'https://www.brandyour.link',
'title': 'My first branded link'
}
)
response.raise_for_status()
link = response.json()
print(f"Short URL: https://{link['shortUrl']}")<?php
$context = stream_context_create([
'http' => [
'method' => 'POST',
'header' => implode("\r\n", [
'Content-Type: application/json',
'apikey: YOUR_API_KEY'
]),
'content' => json_encode([
'destination' => 'https://www.brandyour.link',
'title' => 'My first branded link'
]),
'ignore_errors' => true
]
]);
$response = file_get_contents('https://api.rebrandly.com/v1/links', false, $context);
if ($response === false) {
throw new RuntimeException('Request failed: ' . error_get_last()['message']);
}
$link = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new RuntimeException('JSON decode error: ' . json_last_error_msg() . ' — response: ' . $response);
}
if (!is_array($link) || !isset($link['shortUrl'])) {
throw new RuntimeException('API error: ' . json_encode($link));
}
echo "Short URL: https://{$link['shortUrl']}";
?>using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
var payload = JsonSerializer.Serialize(new {
destination = "https://www.brandyour.link",
title = "My first branded link"
});
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("apikey", "YOUR_API_KEY");
var response = await client.PostAsync(
"https://api.rebrandly.com/v1/links",
new StringContent(payload, Encoding.UTF8, "application/json")
);
response.EnsureSuccessStatusCode();
var link = JsonSerializer.Deserialize<JsonElement>(
await response.Content.ReadAsStringAsync()
);
Console.WriteLine($"Short URL: https://{link.GetProperty("shortUrl").GetString()}");A successful response returns the created link object:
{
"id": "m5jk4cc5bjop45d6",
"title": "My first branded link",
"slashtag": "abc123",
"destination": "https://www.brandyour.link",
"shortUrl": "rebrand.ly/abc123",
"domain": {
"id": "8f104cc5b6ee4a4ba7897b06ac2ddcfb",
"fullName": "rebrand.ly"
},
"createdAt": "2026-01-01T00:00:00.000Z",
"updatedAt": "2026-01-01T00:00:00.000Z"
}For the full parameter reference, see Creating a new link.
