analytics
Analytics API Endpoint: Get real-time analytical data for posts and social accounts, such as clicks, likes, shares, followers, and impressions.
❗Click the › in the endpoint to view details.
get
https://app.ayrshare.com/api
/analytics/links
Analytics on a Shortened Link
Get shortened link analytics. Note, click counts could take up to an hour to reflect in the analytics data.
Premium or Business Plan required.
Parameters
Query
lastDays
number
Get history of links posted over the past n days. Range 1-30 days. Defaults to 1.
Header
Authorization*
string
Format:
Authorization: Bearer API_KEY
. See Overview for more information.Responses
200
Array of shortened link analytics
404
Post ID incorrect
cURL
Node.js
Python
PHP
C#
curl \
-H "Authorization: Bearer API_Key" \
-H 'Content-Type: application/json' \
-X GET https://app.ayrshare.com/api/analytics/links?lastDays=2
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);
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
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/analytics/links?lastDays=' . $lastdays,
[
'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/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
https://app.ayrshare.com/api
/analytics/post
Analytics on a Post
Get real-time analytics such as likes, impressions, retweets, etc for a given post that originated via Ayrshare. Will only return the analytics of networks where the post was sent.
Notes
⮕ Only Facebook Pages, Instagram, Twitter, LinkedIn, Pinterest, TikTok, and YouTube are currently supported.
⮕ You might need to unlink and re-link Facebook and Instagram in the Dashboard's Social Accounts Page to grant the new Analytics permissions.
⮕ Twitter Threads returns as an Array of objects, with each object corresponding to a Tweet in the Thread.
⮕ YouTube can take up to 24 hours to process analytics for videos with fewer views.
Premium or Business Plan required.
Parameters
Header
Authentication*
string
Format:
Authorization: Bearer API_KEY
. See Overview for more information.Body
id*
string
Post ID returned from the /post endpoint. This is the top level "id" returned and not the ids in "postIds".
platforms
array
String array of platforms to retrieve analytics. For example:
["instagram", "facebook", "twitter", "linkedin", "tiktok", "youtube", "pinterest"]
.
If platforms is not included, all the analytics on all of the social networks the post was sent will be returned.
Responses
200: OK
Successful return of analytics
404: Not Found
Error getting post analytics at social networks
404: Not Found
Top level post ID not found
cURL
Node.js
Python
PHP
Go
C#
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"id": "Post ID", "platforms": ["facebook", "instagram", "twitter", "youtube", "tiktok", "linkedin", "pinterest"]}' \
-X POST https://app.ayrshare.com/api/analytics/post
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", "tiktok", "linkedin", "pinterest"], // optional
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'id': 'Post ID',
'platforms': ['facebook', 'instagram', 'twitter', 'youtube', 'tiktok', 'linkedin', 'pinterest']}
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
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/post',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'id' => 'Post ID',
'platforms' => ['facebook', 'instagram', 'twitter', 'youtube', 'tiktok', 'linkedin', 'pinterest'], // 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{}{
"id": "Post ID",
"platforms": []string{"facebook", "instagram", "twitter", "youtube", "tiktok, "linkedin", "pinterest"},
}
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()
}
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\", \"tiktok\", \"linkedin\", \"pinterest\" ]";
streamWriter.Write(json);
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
Console.WriteLine(response);
}
}
}
}
post
https://app.ayrshare.com/api
/analytics/social
Analytics on a Social Network
Get analytics and demographics on a user's social profile, such as impressions, views, and followers.
Currently available for Facebook Pages, Instagram Accounts, Twitter handles, LinkedIn Company Pages, YouTube Channels, Google My Business accounts, TikTok accounts, Reddit, and Pinterest Users.
⮕ Facebook Page analytics is generally only available on Pages with 100 or more likes, such as demographics. Facebook typically updates their metrics once every 24 hours.
⮕ LinkedIn only supports Company Page analytics and limited LinkedIn Personal Page analytics. LinkedIn
count
totals are eventually consistent, but not immediately consistent, and can take up to 24-48 hours in some cases.Parameters
Header
Authorization*
string
Format:
Authorization: Bearer API_KEY
. See Overview for more information.Body
platforms*
array
Social media platforms to get analytics. Accepts an array of Strings with values:
facebook
, gmb
, instagram
, linkedin
, pinterest
, reddit
, tiktok
, twitter
, youtube
.Responses
200
Successful response for social analytics
400: Bad Request
Error response if missing or wrong platform
cURL
Node.js
Python
PHP
Go
C#
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"platforms": ["facebook", "instagram", "twitter", "linkedin", "pinterest", "youtube", "tiktok"]}' \
-X POST https://app.ayrshare.com/api/analytics/social
const fetch = require("node-fetch");
const API_KEY = "API_KEY";
fetch("https://app.ayrshare.com/api/analytics/social", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${API_KEY}`
},
body: JSON.stringify({
platforms: ["facebook", "instagram", "twitter", "linkedin", "pinterest", "tiktok", "youtube"], // required
}),
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'platforms': ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok']}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://app.ayrshare.com/api/analytics/social',
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/social',
[
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer API_KEY'
],
'json' => [
'platforms' => ['facebook', 'instagram', 'twitter', 'linkedin', 'pinterest', 'youtube', 'tiktok'], // required
]
]
);
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{}{
"platforms": []string{"facebook", "instagram", "twitter", "linkedin", "pinterest", "youtube", "tiktok"},
}
bytesRepresentation, err := json.Marshal(message)
if err != nil {
log.Fatalln(err)
}
req, _ := http.NewRequest("POST", "https://app.ayrshare.com/api/social",
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/social";
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 = "\"platforms\" : [ \"facebook\", \"instagram\", \"twitter\", \"linkedin\", \"pinterest\", \"youtube\", \"tiktok\" ]";
streamWriter.Write(json);
streamWriter.Flush();
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var response = streamReader.ReadToEnd();
Console.WriteLine(response);
}
}
}
}
Social Media API Analytics Overview
post
https://app.ayrshare.com
/api/analytics/post
Analytics by Social ID
Retrieve analytics for posts that did not originate via Ayrshare by providing the low-level social post ID. This ID is returned in the
postIds
field of the /post endpoint.Use the Get All Post History endpoint to retrieve posts and IDs originating outside of Ayrshare found in the
id
field.The linked account must the owner of the post to retrieve the analytics. Support platforms: Facebook, Instagram, LinkedIn, YouTube, and Twitter.
Recommend to only use for posts not sent via Ayrshare.
Available for Business Plan users only.
Parameters
Header
Authorization*
string
Format:
Authorization: Bearer API_KEY
. See Overview for more information.Body
id*
string
Low-level post ID from /post endpoint
platforms*
array
Only one value accepted:
facebook
, instagram
, linkedin
, tiktok
, twitter
, youtube
searchPlatformId*
boolean
Always equals
true
Responses
200: OK
Successful return of analytics
Available for Business Plan users only.
{
"id": "108908592035456_102646726003811", // ID from Facebook
"platforms": [
"facebook" // Select only one platform at a time: facebook, instagram, youtube, or twitter
],
"searchPlatformId": true
}
get
https://app.ayrshare.com
/api/analytics/youTubePlaylists
YouTube Playlists
Get the YouTube playlists for the connected YouTube channel.
Parameters
Header
Authorization*
string
Format:
Authorization: Bearer API_KEY
. See Overview for more information.Responses
200: OK
Successful return of playlists
cURL
Node.js
Python
PHP
C#
curl \
-H "Authorization: Bearer API_KEY" \
-X GET https://app.ayrshare.com/api/analytics/youTubePlaylists
const fetch = require("node-fetch");
const API_KEY = "API_KEY";
fetch("https://app.ayrshare.com/api/analytics/youTubePlaylists", {
method: "GET",
headers: {
"Authorization": `Bearer ${API_KEY}`
}
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {'Authorization': 'Bearer API_KEY'}
r = requests.get('https://app.ayrshare.com/api/analytics/youTubePlaylists', 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(
'GET',
'https://app.ayrshare.com/api/analytics/youTubePlaylists',
[
'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 HistoryGETRequest_charp
{
class History
{
static void Main(string[] args)
{
string API_KEY = "API_KEY";
string url = "https://app.ayrshare.com/api/analytics/youTubePlaylists";
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);
}
}
}
}
Last modified 6h ago