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

Link Shortener API Endpoint

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.
❗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
1
curl \
2
-H "Authorization: Bearer API_KEY" \
3
-H 'Content-Type: application/json' \
4
-d '{"url": "https://www.ayrshare.com"}' \
5
-X POST https://app.ayrshare.com/api/shorten
Copied!
1
const fetch = require("node-fetch");
2
const API_KEY = "API_KEY";
3
const url = "https://www.ayrshare.com";
4
​
5
fetch("https://app.ayrshare.com/api/shorten", {
6
method: "POST",
7
headers: {
8
"Content-Type": "application/json",
9
"Authorization": `Bearer ${API_KEY}`
10
},
11
body: JSON.stringify({ url }),
12
})
13
.then((res) => res.json())
14
.then((json) => console.log(json))
15
.catch(console.error);
Copied!
1
import requests
2
​
3
payload = {'url': 'https://www.ayrshare.com'}
4
headers = {'Content-Type': 'application/json',
5
'Authorization': 'Bearer API_KEY'}
6
​
7
r = requests.post('https://app.ayrshare.com/api/shorten',
8
json=payload,
9
headers=headers)
10
11
print(r.json())
Copied!
1
<?php
2
require 'vendor/autoload.php'; // Composer auto-loader using Guzzle. See https://docs.guzzlephp.org/en/stable/overview.html
3
​
4
$client = new GuzzleHttp\Client();
5
$res = $client->request(
6
'POST',
7
'https://app.ayrshare.com/api/shorten',
8
[
9
'headers' => [
10
'Content-Type' => 'application/json',
11
'Authorization' => 'Bearer API_KEY'
12
],
13
'url' => ['https://www.ayrshare.com'],
14
]
15
);
16
​
17
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
Copied!

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
Last modified 8d ago