analytics

Get real-time analytical data for posts, such as clicks, likes, shares, and impressions.
https://app.ayrshare.com/api/analytics/links
Get shortened link analytics.
Request
Response
Request
Headers
Authorization
required
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
Query Parameters
lastDays
optional
number
Last X days of link history. Range 1-7 days. Default 1 day.
Response
200: OK
Array of shortened link analytics
[
{
"linkEventStats": [
{
"count": "6",
"event": "CLICK",
"platform": "OTHER"
},
{
"count": "1",
"event": "CLICK",
"platform": "IOS"
}
],
"link": "https://bookriot.com/book-riots-deals-of-the-day-for-september-27-2020/",
"shortLink": "https://ayr.app/l/Nz3L",
"created": {
"_seconds": 1601215211,
"_nanoseconds": 413000000
}
},
{
"linkEventStats": [
{
"count": "11",
"event": "CLICK",
"platform": "OTHER"
},
{
"count": "2",
"event": "CLICK",
"platform": "IOS"
}
],
"link": "https://neilpatel.com/blog/reputation-management-agency/",
"shortLink": "https://ayr.app/l/TSdN",
"created": {
"_seconds": 1601223003,
"_nanoseconds": 7000000
}
}
]
404: Not Found
Post ID incorrect
{
"action": "analytics",
"status": "error",
"code": 186,
"message": "Post ID not found.",
"id": "IHvCmacgIc6hMU9IQ6C"
}

Request Example

cURL
Node.js
Python
PHP
C#
cURL
curl \
-H "Authorization: Bearer API_Key" \
-H 'Content-Type: application/json' \
-X GET https://app.ayrshare.com/api/analytics/links?lastDays=2
Node.js
const fetch = require("node-fetch");
const API_KEY = "API_KEY";
const lastDays = 2;
fetch(`https://app.ayrshare.com/api/analytics/links?lastDays=${lastDays}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
}
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
Python
import requests
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.delete('https://app.ayrshare.com/api/analytics/links?lastDays=2',
headers=headers)
print(r.json())
PHP
<?php
require 'vendor/autoload.php'; // Composer auto-loader
$lastdays = "2";
$client = new GuzzleHttp\Client();
$res = $client->request(
'GET',
'https://app.ayrshare.com/api/analytics/links?lastDays=' . $lastdays,
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
C#
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/analytics/links";
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);
}
}
}
}

post
/post

https://app.ayrshare.com/api/analytics/post
Get real-time analytics such as likes, impressions, retweets, etc for a given post ID. Note: Only Twitter and LinkedIn is currently supported. Additional networks coming soon.
Request
Response
Request
Headers
Authentication
required
string
Format: Authorization: Bearer API_KEY. See Overview for more information.
Body Parameters
id
required
string
Post ID returned from the /post endpoint.
platforms
required
array
String array of platforms to retrieve analytics. For example: ["twitter", "linkedin"].
Response
200: OK
Successful return of analytics
{
"twitter": {
"id": "1313589441919827982",
"analytics": {
"text": "Today is a great day!",
"non_public_metrics": {
"user_profile_clicks": 12,
"impression_count": 76
},
"organic_metrics": {
"like_count": 4,
"retweet_count": 11,
"user_profile_clicks": 2,
"reply_count": 3,
"impression_count": 1920
},
"id": "1313589441919827982"
}
},
"status": "success",
"code": 200,
"id": "IHvCLacgPc6hMU9IQ6oK"
}

Request Example

cURL
Node.js
Python
PHP
Go
C#
cURL
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"id": "Post ID", "platforms": ["twitter", "facebook", "instagram", "linkedin"]}' \
-X POST https://app.ayrshare.com/api/analytics/post
Node.js
const fetch = require("node-fetch");
const API_KEY = "API_KEY";
fetch("https://app.ayrshare.com/api/analytics/post", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
id: "Post ID", // required
platforms: ["twitter", "facebook", "instagram", "linkedin"], // required
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
Python
import requests
payload = {'id': 'Post ID',
'platforms': ['twitter', 'facebook', 'instagram', 'linkedin']}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://app.ayrshare.com/api/analytics/post',
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/post',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'id' => 'Post ID',
'platforms' => ['twitter', 'facebook', 'instagram', 'linkedin'], // required
]
]
);
echo json_encode(json_decode($res->getBody()), JSON_PRETTY_PRINT);
Go
package main
import (
"bytes"
"encoding/json"
"log"
"net/http"
)
func main() {
message := map[string]interface{}{
"id": "Post ID",
"platforms": []string{"twitter", "facebook", "instagram", "linkedin"},
}
bytesRepresentation, err := json.Marshal(message)
if err != nil {
log.Fatalln(err)
}
req, _ := http.NewRequest("POST", "https://app.ayrshare.com/api/post",
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()
}
C#
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/post";
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 = "{\"id\" : \"Post ID\","
+ "\"platforms\" : [ \"twitter\", \"facebook\", \"instagram\", \"linkedin\" ]";
streamWriter.Write(json);
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
Console.WriteLine(response);
}
}
}
}