Skip to main content

📊 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 shortUrl or linkId
  • Both parameters cannot be empty
  • Use shortUrl for easier identification
  • Use linkId for programmatic access
Analytics Parameters
ParameterTypeRequiredDescriptionExample
shortUrlstringNo*The short URL of the link to get analytics forhttps://yourapp.chottu.link/abc123
linkIdstringNo*The unique ID of the link to get analytics for39629a6d-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"
}'
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
FieldTypeDescriptionExample
clicks_last_30_daysintegerNumber of clicks in the last 30 days150
clicks_last_7_daysintegerNumber of clicks in the last 7 days45
total_clicksintegerTotal number of clicks since link creation1250

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."
}
]
}

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​

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);
});

Best Practices​

Implementation Tips:
  • Parameter Validation: Always validate that either shortUrl or linkId is 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​

  1. Choose the Right Parameter: Use shortUrl for human-readable identification, linkId for programmatic access
  2. Handle Zero Clicks: Always handle cases where clicks are 0
  3. Monitor Trends: Track analytics over time to identify patterns
  4. Cache Results: Cache analytics data for frequently accessed links
  5. Error Recovery: Implement retry logic for network failures

Error Handling Best Practices​

  1. Check HTTP Status Codes: Always verify response status
  2. Handle Network Errors: Implement retry logic for network failures
  3. Validate Response Format: Ensure response structure is as expected
  4. Log Errors: Log API errors for debugging purposes
  5. 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.