Links

links

Link shortener and analytics endpoint
With the links endpoint your can shorten links to include in social posts.
Max Pack Required
Max Pack Required
The Ayrshare link shortener offers several valuable benefits social publishing.
  • Condense long and complex URLs for more visually appealing, concise, and memorable.
  • Analytics and tracking capabilities, allowing you to monitor link performance, engagement, and audience insights.
  • Save valuable character space, especially on platforms like Twitter where character limits are stringent.
  • Add a custom link domain with your own url.

Request Examples

cURL
Node.js
Python
PHP
Go
C#
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url": "https://www.ayrshare.com", "utmSource": "google_ads"}' \
-X POST https://app.ayrshare.com/api/links
const API_KEY = "API_KEY";
fetch("https://app.ayrshare.com/api/links", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
url: "https://www.ayrshare.com", // required
utmSource: ""google_ads", // optional
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'url': 'https://www.ayrshare.com',
'utmSource': 'google_ads"}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://app.ayrshare.com/api/links',
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/links',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'url' => 'https://www.ayrshare.com',
'utmSource' => 'google_ads', // optional
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
)
func main() {
message := map[string]interface{}{
"url": "https://www.ayrshare.com",
"utmSource": "goggle_ads",
}
bytesRepresentation, err := json.Marshal(message)
if err != nil {
log.Fatalln(err)
}
req, _ := http.NewRequest("POST", "https://app.ayrshare.com/api/links",
bytes.NewBuffer(bytesRepresentation))
req.Header.Add("Content-Type", "application/json; charset=UTF-8")
req.Header.Add("Authorization", "Bearer API_KEY")
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal("Error:", err)
}
res.Body.Close()
}
using System;
using System.Net;
using System.IO;
namespace PostAnalyticsPOSTRequest_charp
{
class PostAnalytics
{
static void Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://app.ayrshare.com/api/analytics/links";
var httpWebRequest = WebRequest.CreateHttp(url);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Method = "POST";
httpWebRequest.Headers.Add("Authorization", "Bearer " + API_KEY);
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
string json = "{\"url\" : \"https://www.ayrshare.com\","
+ "\"utmSource\" :\"google_ads\"";
streamWriter.Write(json);
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
Console.WriteLine(response);
}
}
}
}

Request Examples

cURL
Node.js
Python
PHP
C#
curl \
-H "Authorization: Bearer API_Key" \
-H 'Content-Type: application/json' \
-X GET https://app.ayrshare.com/api/links/yC0fTl
const API_KEY = "API_KEY";
fetch(`https://app.ayrshare.com/api/links/yC0fTl`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
}
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.delete('https://app.ayrshare.com/api/links/yC0fTl',
headers=headers)
print(r.json())
<?php
require 'vendor/autoload.php'; // Composer auto-loader using Guzzle. See https://docs.guzzlephp.org/en/stable/overview.html
$lastdays = "2";
$client = new GuzzleHttp\Client();
$res = $client->request(
'GET',
'https://app.ayrshare.com/api/links/yC0fTl',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
using System;
using System.Net;
using System.IO;
namespace LinksGETRequest_charp
{
class Links
{
static void Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://app.ayrshare.com/api/links/yC0fTl";
var httpWebRequest = WebRequest.CreateHttp(url);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Headers.Add("Authorization", "Bearer " + API_KEY);
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
Console.WriteLine(response);
}
}
}
}
A custom link domain allows you to personalize and brand the domain name used for link shortening and redirection. Instead of using a generic link shortener domain (e.g., bit.ly, ayr.app), a custom link domain allows you to use own domain name to create shortened links.
Max Pack Required
Max Pack and Business Plan required.
Please contact us to set up your custom domain.
Last modified 1mo ago