short
Short API Endpoint: Shorten links using Ayrshare's URL shortener.

The /short endpoint can be used as a URL shortener. POST a URL, such as a website, to the endpoint and a shortened link is returned. URLs in the post body of the /post endpoint are automatically shortened and can be disabled with shortenLinks=false parameter.
A URL shortener reduces the size of a URL to make it more readable, saves characters, which is especially important for social networks such as Twitter, and allows analytics tracking of impressions and clicks. Shortened links use the ayr.app domain.
A custom URL shortener, known as a branded URL shortener, is available for Enterprise Plans.
Premium or Business Plan required.
❗Click the β€Ί in the endpoint to view details.
post
https://app.ayrshare.com/api
/short
Shorten a URL

Request Examples

cURL
Node.js
Python
PHP
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url": "https://www.ayrshare.com"}' \
-X POST https://app.ayrshare.com/api/shorten
const fetch = require("node-fetch");
const API_KEY = "API_KEY";
const url = "https://www.ayrshare.com";
​
fetch("https://app.ayrshare.com/api/shorten", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({ url }),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
​
payload = {'url': 'https://www.ayrshare.com'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
​
r = requests.post('https://app.ayrshare.com/api/shorten',
json=payload,
headers=headers)
print(r.json())
<?php
require 'vendor/autoload.php'; // Composer auto-loader using Guzzle. See https://docs.guzzlephp.org/en/stable/overview.html
​
$client = new GuzzleHttp\Client();
$res = $client->request(
'POST',
'https://app.ayrshare.com/api/shorten',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'url' => ['https://www.ayrshare.com'],
]
]
);
​
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
When creating the shortened URL, you may also specify social media metadata for the link preview. The title, description, and image can be set. For example:
Link Preview Metadata
The above Tweet preview link was created with the following:
{
"url": "https://www.ayrshare.com",
"socialMeta": {
"title": "Social Media with an API",
"description": "Social done right with an API. The only way to go!",
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg"
}
}
All fields are required or the metadata will not be set.
  • title: The preview title.
  • description: Body description of the preview.
  • mediaUrl: URL to the image used by the preview. The image should be at least 300x200 px, and less than 300 KB.
Social metadata is passed to Twitter, Facebook, Facebook Messenger, iMessage, WhatsApp, and other services.

Bitly Integration

You may use your own link shortener, such as Bit.ly, by providing us with the API key from the link shortening service. This allows you to use a custom domain when shortening the link. Please contact us for more information.
Available for Premium and Business Plans
Copy link
On this page
Link Shortener API Endpoint
post
Shorten a URL
Request Examples
Social Media Link Preview
Bitly Integration