Get Short Link Metrics by City

POST /api/v1/analytics

Common errors include:

  • "Bad Request" if body parameters are not passed
  • "DNS_CONFIGURATION_ERROR" if custom domain DNS is misconfigured.

The createQrCodeHandler creates a qr code for the input body and returns the reponse to users

Request

Method : POST
Content-Type : Application/json

URL Parameters Schema

shortlink string Required
Default: N/A
The URL to analyze (e.g., "https://kut.lt/d3i1t”)
startDate string Required
Default: N/A
Start date in YYYY-MM-DD format
endDate string Required
Default: N/A
End date in YYYY-MM-DD format
plan string Required
Default: N/A
User's plan type ("STARTER", "STANDARDRD", "SUPER".)
linkAnalytics number
Default: null
Limit number of analytics entries
kind string Required
Default: null
city
LANGUAGE
REQUEST
 curl -X POST \
  'https://divsly-backend.vercel.app/api/v1/analytics' \
  -H 'Authorization: Bearer YOUR_JWT_TOKEN_HERE' \
  -H 'Content-Type: application/json' \
  -d '{
    "shortlink": "https://kut.lt/d3i1t",
    "startDate": "2024-03-01",
    "endDate": "2024-03-25",
    "plan": "STARTER",
    "linkAnalytics": 5,
    "kind": "city"
   }'
API REQUEST
 const getCityAnalytics = (analyticsData) => {
  return new Promise((resolve, reject) => {
    fetch('https://divsly-backend.vercel.app/api/v1/analytics', {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_JWT_TOKEN_HERE',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        shortlink: analyticsData.shortlink,
        startDate: analyticsData.startDate,
        endDate: analyticsData.endDate,
        plan: analyticsData.plan,
        linkAnalytics: analyticsData.linkAnalytics,
        kind: analyticsData.kind
      })
    })
      .then(response => response.json())
      .then(data => resolve(data))
      .catch(error => reject(error));
  });
};

const cityAnalyticsData = {
  shortlink: "https://kut.lt/d3i1t",
  startDate: "2024-03-01",
  endDate: "2024-03-25",
  plan: "STARTER",
  linkAnalytics: 5,
  kind: "city"
};

getCityAnalytics(cityAnalyticsData)
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));                   
API REQUEST
 const axios = require('axios');

const getCityAnalytics = (analyticsData) => {
  return new Promise((resolve, reject) => {
    axios({
      method: 'post',
      url: 'https://divsly-backend.vercel.app/api/v1/analytics',
      headers: {
        'Authorization': 'Bearer YOUR_JWT_TOKEN_HERE',
        'Content-Type': 'application/json'
      },
      data: {
        shortlink: analyticsData.shortlink,
        startDate: analyticsData.startDate,
        endDate: analyticsData.endDate,
        plan: analyticsData.plan,
        linkAnalytics: analyticsData.linkAnalytics,
        kind: analyticsData.kind
      }
    })
      .then(response => resolve(response.data))
      .catch(error => reject(error.response.data));
  });
};

const cityAnalyticsData = {
  shortlink: "https://kut.lt/d3i1t",
  startDate: "2024-03-01",
  endDate: "2024-03-25",
  plan: "STARTER",
  linkAnalytics: 5,
  kind: "city"
};

getCityAnalytics(cityAnalyticsData)
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

API REQUEST
 $data = array(
    'shortlink' => 'https://kut.lt/d3i1t',
    'startDate' => '2024-03-01',
    'endDate' => '2024-03-25',
    'plan' => 'STARTER',
    'linkAnalytics' => 5,
    'kind' => 'city'
);

    $ch = curl_init('https://divsly-backend.vercel.app/api/v1/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_JWT_TOKEN_HERE',
        '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);

API REQUEST
 import requests
 import json

  url = 'https://divsly-backend.vercel.app/api/v1/analytics'
  headers = {
    'Authorization': 'Bearer YOUR_JWT_TOKEN_HERE',
    'Content-Type': 'application/json'
  }
  data = {
    'shortlink': 'https://kut.lt/d3i1t',
    'startDate': '2024-03-01',
    'endDate': '2024-03-25',
    'plan': 'STARTER',
    'linkAnalytics': 5,
    'kind': 'city'
 }

  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}")
RESPONSE
  {
  "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."
 }