shorten
Shorten links using Ayrshare's link shortener.

URL Shortener REST API

The /shorten endpoint can be used as a URL shortener REST API to created a shorten link. You can also automatically shorten links in the post body by using the shortenLinks=true parameter in the /post endpoint.
Click the › in the endpoint to view details.
post
https://app.ayrshare.com/api
/shorten
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
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!
Last modified 12d ago