Retrieves city-level analytics data for a short link filtered by one or more countries.
curl -X POST \
'https://apis.divsly.com/api/v1/city-analytics' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"shortlink": "https://sl.gy/my-link",
"startDate": "2024-03-01",
"endDate": "2024-03-25",
"plan": "STARTER",
"linkAnalytics": 5,
"kind": "city"
}'
const getCityAnalytics = (analyticsData) => {
return new Promise((resolve, reject) => {
fetch('https://apis.divsly.com/api/v1/city-analytics', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
body: JSON.stringify({
shortlink: analyticsData.shortlink,
countries: analyticsData.countries
})
})
.then(response => response.json())
.then(data => resolve(data))
.catch(error => reject(error));
});
};
const cityAnalyticsData = {
shortlink: "https://sl.gy/my-link",
countries: ["India", "United States"]
};
getCityAnalytics(cityAnalyticsData)
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
const axios = require('axios');
const getCityAnalytics = (analyticsData) => {
return new Promise((resolve, reject) => {
axios({
method: 'post',
url: 'https://apis.divsly.com/api/v1/city-analytics',
headers: {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
},
data: {
shortlink: analyticsData.shortlink,
countries: analyticsData.countries
}
})
.then(response => resolve(response.data))
.catch(error => reject(error.response.data));
});
};
const cityAnalyticsData = {
shortlink: "https://sl.gy/my-link",
countries: ["India", "United States"]
};
getCityAnalytics(cityAnalyticsData)
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
$data = array(
'shortlink' => 'https://sl.gy/my-link',
'countries' => array('India', 'United States')
);
$ch = curl_init('https://apis.divsly.com/api/v1/city-analytics');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer YOUR_ACCESS_TOKEN',
'Content-Type: application/json'
));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$result = json_decode($response, true);
print_r($result);
import requests
import json
url = 'https://apis.divsly.com/api/v1/city-analytics'
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
'Content-Type': 'application/json'
}
data = {
'shortlink': 'https://sl.gy/my-link',
'countries': ['India', 'United States']
}
try:
response = requests.post(
url,
headers=headers,
json=data
)
response.raise_for_status()
print(response.json())
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
{
"message": "Analytics fetched successfully",
"success": true,
"resultData": {
"city": [
{
"city": "New York",
"_count": {
"_all": 45,
"city": 45
}
},
{
"city": "Mumbai",
"_count": {
"_all": 30,
"city": 30
}
}
]
}
}
{
"message": "Unauthorized!"
}
{
"message": "Quota not found.!"
}
{
"message": "Internal server error."
}