shorten

post
Shorten a URL

https://app.ayrshare.com/api/shorten
URL Shortener. Submit a URL and get a shortened URL to save characters. This is helpful when you want to conserve your character count on Twitter. Note: in the /post endpoint you automatically shorten URLs in the post text.
Request
Response
Request
Headers
Authorization
optional
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
Body Parameters
url
required
string
URL to be shortened. Must be a valid URL starting with "http"
Response
200: OK
Return of the shortened URL
https://ayr.app/l/unique

Request Examples

cURL
Node.js
Python
PHP
cURL
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
Node.js
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);
Python
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
<?php
require 'vendor/autoload.php'; // Composer auto-loader
$client = new GuzzleHttp\Client();
$res = $client->request(
'POST',
'https://app.ayrshare.com/api/shorten',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'url' => ['https://www.ayrshare.com'],
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);