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. Premium or Business Plan required.
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 Examples

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
Analytics on a Post

https://app.ayrshare.com/api/analytics/post
Get real-time analytics such as likes, impressions, retweets, etc for a given post ID. Will only return the analytics of networks where the post was sent. Note 1: Only Facebook, Instagram, Twitter, LinkedIn Company Pages, and YouTube are currently supported. Note 2: You might need to unlink and re-link Facebook and Instagram in the Dashboard's Social Accounts Page to grant the new Analytics permissions. Premium or Business Plan required.
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. This is the top level "id" returned and not the ids in "postIds".
platforms
required
array
String array of platforms to retrieve analytics. For example: ["instagram", "facebook", "twitter", "linkedin", "youtube"].
Response
200: OK
Successful return of analytics
{
"facebook": {
"id": "1397547544885713_2159201585286968",
"analytics": {
"impressionsUnique": 15,
"engagedUsers": 1,
"clicksUnique": 0,
"likeReaction": 1
}
},
"instagram": {
"id": "17856916804532520",
"analytics": {
"engagementCount": 10,
"impressionsCount": 73,
"reachCount": 71,
"savedCount": 0
}
},
"twitter": {
"id": "1313589441919827982",
"analytics": {
"text": "Today is a great day!",
"nonPublicMetrics": {
"userProfileClicks": 12,
"impressionCount": 76
},
"organicMetrics": {
"likeCount": 4,
"retweetCount": 11,
"userProfileClicks": 2,
"replyCount": 3,
"impressionCount": 1920
},
"id": "1313589441919827982"
}
},
"linkedin": {
"id": "6783586276949000192",
"analytics": {
"shareCount": 12,
"likeCount": 43,
"engagement": 93,
"clickCount": 3,
"impressionCount": 342,
"commentCount": 2
}
},
"youtube": {
"id": "RWJMpOUGicU",
"analytics": {
"viewCount": 123,
"commentCount": 14,
"likeCount": 56,
"dislikeCount": 2,
"clickCount": 50,
"estimatedMinutesWatched": 43
},
"status": "success",
"code": 200,
"id": "IHvCLacgPc6hMU9IQ6oK"
}
404: Not Found
Post Id not found
{
"action": "analytics",
"status": "error",
"code": 186,
"message": "Post ID not found.",
"id": "7aVBe0jw27DNwFq92KZ"
}

Request Examples

cURL
Node.js
Python
PHP
Go
C#
cURL
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"id": "Post ID", "platforms": ["facebook", "instagram", "twitter", "youtube", "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: ["facebook", "instagram", "twitter", "youtube", "linkedin"], // required
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
Python
import requests
payload = {'id': 'Post ID',
'platforms': ['facebook', 'instagram', 'twitter', 'youtube', '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' => ['facebook', 'instagram', 'twitter', 'youtube', '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{"facebook", "instagram", "twitter", "youtube", "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\" : [ \"facebook\", \"instagram\", \"twitter\", \"youtube\", \"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);
}
}
}
}

Analytics for Profiles

Analytics a post for a particular user profile by passing the profileKey parameter as a String in the body.

Business or Enterprise Plan required.

const fetch = require("node-fetch");
const API_KEY = "API_KEY";
const PROFILE_KEY = "PROFILE_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: ["facebook", "instagram", "twitter", "youtube", "linkedin"], // required
profileKey: PROFILE_KEY // Profile key as a String
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);