📊 Get Analytics via REST API
Use ChottuLink's REST API to retrieve analytics data for your dynamic links. This endpoint provides detailed click statistics including total clicks, 7-day clicks, and 30-day clicks for any specific link in your account.
Endpoint​
POST https://api2.chottulink.com/chotuCore/pa/v1/analytics
Authentication​
Include your API key in the request header:
API-KEY: c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
API Key Replacement Required
Replace c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx with your actual REST API integration key from
the ChottuLink Dashboard.
Request Parameters​
Parameter Guidelines:
- You must provide either
shortUrlorlinkId - Both parameters cannot be empty
- Use
shortUrlfor easier identification - Use
linkIdfor programmatic access
Analytics Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| shortUrl | string | No* | The short URL of the link to get analytics for | https://yourapp.chottu.link/abc123 |
| linkId | string | No* | The unique ID of the link to get analytics for | 39629a6d-e0cf-432e-938a-a10c5ea88aaa |
*Either shortUrl or linkId must be provided
Example Request​
Using Short URL​
curl --location 'https://api2.chottulink.com/chotuCore/pa/v1/analytics' \
--header 'API-KEY: c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data '{
"shortUrl": "https://yourapp.chottu.link/abc123"
}'
Using Link ID​
curl --location 'https://api2.chottulink.com/chotuCore/pa/v1/analytics' \
--header 'API-KEY: c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data '{
"linkId": "39629a6d-e0cf-432e-938a-a10c5ea88aaa"
}'
Response​
Success Response​
Status Code: 200 OK
{
"clicks_last_30_days": 150,
"clicks_last_7_days": 45,
"total_clicks": 1250
}
Response Fields​
Analytics Object Fields
| Field | Type | Description | Example |
|---|---|---|---|
| clicks_last_30_days | integer | Number of clicks in the last 30 days | 150 |
| clicks_last_7_days | integer | Number of clicks in the last 7 days | 45 |
| total_clicks | integer | Total number of clicks since link creation | 1250 |
Error Responses​
Missing Parameters​
Status Code: 400 Bad Request
{
"code": 101,
"errorMessage": "There was one or more validation error(s)",
"errors": [
{
"errorMessage": "REQUIRED_FIELD_MISSING",
"fieldName": "Both 'shortUrl' and 'linkId' cannot be empty. At least one must be provided."
}
]
}
Invalid Link​
Status Code: 400 Bad Request
{
"code": 103,
"errorMessage": "The requested entity could not be found",
"error": {
"errorMessage": "Invalid link details. We were unable to retrieve analytics for the provided link. Please verify the information and try again.",
"fieldName": "INVALID_VALUE"
}
}
Unauthorized Access​
Status Code: 401 Unauthorized
{
"code": 130,
"errorMessage": "Authorization Failed!",
"error": {
"errorMessage": "Invalid Api Key",
"fieldName": "UNAUTHORIZED_ACCESS"
}
}
Usage Examples​
- JavaScript
- Python
- PHP
- Node.js
- cURL
const axios = require('axios');
async function getAnalytics(shortUrl) {
try {
const response = await axios.post(
'https://api2.chottulink.com/chotuCore/pa/v1/analytics',
{
shortUrl: shortUrl
},
{
headers: {
'API-KEY': 'c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'Content-Type': 'application/json'
}
}
);
return response.data;
} catch (error) {
console.error('Error fetching analytics:', error.response?.data || error.message);
throw error;
}
}
// Usage
getAnalytics('https://yourapp.chottu.link/abc123').then(data => {
console.log('Total clicks:', data.total_clicks);
console.log('Last 7 days:', data.clicks_last_7_days);
console.log('Last 30 days:', data.clicks_last_30_days);
});
import requests
def get_analytics(short_url=None, link_id=None):
url = "https://api2.chottulink.com/chotuCore/pa/v1/analytics"
headers = {
'API-KEY': 'c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'Content-Type': 'application/json'
}
# Prepare payload
payload = {}
if short_url:
payload['shortUrl'] = short_url
elif link_id:
payload['linkId'] = link_id
else:
raise ValueError("Either short_url or link_id must be provided")
try:
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error fetching analytics: {e}")
raise
# Usage
data = get_analytics(short_url="https://yourapp.chottu.link/abc123")
print("Total clicks:", data['total_clicks'])
print("Last 7 days:", data['clicks_last_7_days'])
print("Last 30 days:", data['clicks_last_30_days'])
<?php
function getAnalytics($shortUrl = null, $linkId = null) {
$url = "https://api2.chottulink.com/chotuCore/pa/v1/analytics";
$headers = [
'API-KEY: c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'Content-Type: application/json'
];
// Prepare payload
$payload = [];
if ($shortUrl) {
$payload['shortUrl'] = $shortUrl;
} elseif ($linkId) {
$payload['linkId'] = $linkId;
} else {
throw new Exception("Either shortUrl or linkId must be provided");
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
return json_decode($response, true);
} else {
throw new Exception("Error fetching analytics: HTTP {$httpCode}");
}
}
// Usage
try {
$data = getAnalytics("https://yourapp.chottu.link/abc123");
echo "Total clicks: " . $data['total_clicks'] . "\n";
echo "Last 7 days: " . $data['clicks_last_7_days'] . "\n";
echo "Last 30 days: " . $data['clicks_last_30_days'] . "\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
?>
const axios = require('axios');
async function getAnalytics(shortUrl) {
try {
const response = await axios.post(
'https://api2.chottulink.com/chotuCore/pa/v1/analytics',
{
shortUrl: shortUrl
},
{
headers: {
'API-KEY': 'c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'Content-Type': 'application/json'
}
}
);
return response.data;
} catch (error) {
console.error('Error fetching analytics:', error.response?.data || error.message);
throw error;
}
}
// Usage
getAnalytics('https://yourapp.chottu.link/abc123').then(data => {
console.log('Analytics:', data);
});
# Using shortUrl
curl --location 'https://api2.chottulink.com/chotuCore/pa/v1/analytics' \
--header 'API-KEY: c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data '{
"shortUrl": "https://yourapp.chottu.link/abc123"
}'
# Using linkId
curl --location 'https://api2.chottulink.com/chotuCore/pa/v1/analytics' \
--header 'API-KEY: c_api_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'Content-Type: application/json' \
--data '{
"linkId": "39629a6d-e0cf-432e-938a-a10c5ea88aaa"
}'
Best Practices​
Implementation Tips:
- Parameter Validation: Always validate that either
shortUrlorlinkIdis provided - Error Handling: Implement proper error handling for all response codes
- Caching: Cache analytics data when appropriate to reduce API calls
- Rate Limiting: Respect API rate limits and implement exponential backoff
- Data Validation: Validate response data before processing
Analytics Best Practices​
- Choose the Right Parameter: Use
shortUrlfor human-readable identification,linkIdfor programmatic access - Handle Zero Clicks: Always handle cases where clicks are 0
- Monitor Trends: Track analytics over time to identify patterns
- Cache Results: Cache analytics data for frequently accessed links
- Error Recovery: Implement retry logic for network failures
Error Handling Best Practices​
- Check HTTP Status Codes: Always verify response status
- Handle Network Errors: Implement retry logic for network failures
- Validate Response Format: Ensure response structure is as expected
- Log Errors: Log API errors for debugging purposes
- User-Friendly Messages: Provide meaningful error messages to users
Rate Limits​
The API is subject to rate limiting. Please contact support for specific rate limit information.