CDN

Create an API Key and access token:-

For create a API Key and Access Token to refer this link :-

https://www.e2enetworks.com/help/knowledge-base/how-to-create-an-api-access-token/

List of CDN

To find the list of CDN, send a HTTP GET request :-

https://api.e2enetworks.com/myaccount/api/v1/cdn/distributions/?apikey={{apikey}}&&page_no=1&per_page=5&project_id={{project-id}}

import http.client

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = ''
headers = {
        'Authorization': 'API_token ',
    }

  conn.request("GET", "/myaccount/api/v1/cdn/distributions/?apikey={{api_key}}&null=null&page_no=1&per_page=5&project_id={{project-id}}", payload, headers)
  res = conn.getresponse()
  data = res.read()
  print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
"code": 200,
"data": [
    {
        "id": 555,
        "domain_id": "E25M1DQYKR0WO9",
        "user_domain_name": "angular.com",
        "e2e_domain_name": "angularlqgv41u3qd.cdn.e2enetworks.net",
        "domain_state": "Deployed",
        "is_enabled": false,
        "created_at": "06/Jun/2022 06:45 PM"
    }
],
"errors": {},
"message": "Success",
"total_page_number": 1,
"total_count": 1
}

Create a new CDN-

To create a CDN , send a Post request :-

https://api.e2enetworks.com/myaccount/api/v1/cdn/distributions/?apikey={{apikey}}&project_id={{project-id}}

import http.client
import json

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = json.dumps({
"cache_details": {
  "allowed_http_methods": "GET|HEAD",
  "default_ttl": 86400,
  "max_ttl": 3153000,
  "min_ttl": 0,
  "viewer_protocol_policy": "https-only"
},
"domain_details": {
  "http_versions": "http2",
  "is_ipv6_supported": False,
  "root_object": ""
},
"domain_name": "shubha.com",
"origin_details": {
  "keepalive_timeout": 5,
  "origin_id": "shubha.com",
  "origin_path": "/path",
  "protocol_policy": "https-only",
  "response_timeout": 30,
  "ssl_protocol": "TLSv1.2"
}
})
headers = {
  'Authorization': 'api_token',
  'Content-Type': 'application/json',
}
conn.request("POST", "/myaccount/api/v1/cdn/distributions/?apikey={{api_key}}&project_id={{project-id}}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
  "cache_details": {
    "allowed_http_methods": "GET|HEAD",
    "default_ttl": 86400,
    "max_ttl": 3153000,
    "min_ttl": 0,
    "viewer_protocol_policy": "https-only"
  },
  "domain_details": {
    "http_versions": "http2",
    "is_ipv6_supported": false,
    "root_object": ""
  },
  "domain_name": "shubha.com",
  "origin_details": {
    "keepalive_timeout": 5,
    "origin_id": "shubha.com",
    "origin_path": "/shubh",
    "protocol_policy": "https-only",
    "response_timeout": 30,
    "ssl_protocol": "TLSv1.2"
  }
}

Delete a CDN -

To delete a CDN , send a DELETE request:-

https://api.e2enetworks.com/myaccount/api/v1/cdn/distributions/?apikey={{apikey}}&domain_id={{domain_id}}&project_id={{project-id}}

import http.client

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = ''
headers = {
          'Authorization': 'api_token ',
    }
conn.request("DELETE", "/myaccount/api/v1/cdn/distributions/?apikey={{api_key}}&domain_id={{domain_id}}&project_id={{project-id}}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
    "code": 200,
    "data": {
        "message": "Your Distribution has been deleted successfully. "
    },
    "errors": {},
    "message": "Success"
}

Enable CDN Distribution

To enable CDN Distribution , send a PUT request :-

https://api.e2enetworks.com/myaccount/api/v1/cdn/distributions/?apikey={{apikey}}&project_id={{project-id}}

import http.client
import json

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = json.dumps({
          "domain_id": "E2LEV9ATODOA3U",
          "is_enabled": True
            })
headers = {
        'Authorization': 'api_token',
        'Content-Type': 'application/json',
      }
conn.request("PUT", "/myaccount/api/v1/cdn/distributions/?apikey={{api_key}}&project_id={{project-id}}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
  "domain_id": "E2LEV9ATODOA3U",
  "is_enabled": true
}

Disable CDN Distribution

To Disable CDN Distribution , send a PUT request-

https://api.e2enetworks.com/myaccount/api/v1/cdn/distributions/?apikey={{apikey}}&project_id={{project-id}}

import http.client
import json

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = json.dumps({
                "domain_id": "E2LEV9ATODOA3U",
              "is_enabled": False
            })
  headers = {
              'Authorization': 'Bearer ',
              'Content-Type': 'application/json',
          }
  conn.request("PUT", "/myaccount/api/v1/cdn/distributions/?apikey={{api_key}}&project_id={{project-id}}", payload, headers)
  res = conn.getresponse()
  data = res.read()
  print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
    {
  "domain_id": "E2LEV9ATODOA3U",
  "is_enabled": false
}

CDN Monitoring

To view CDN Monitoring data to send a GET request-

https://api.e2enetworks.com/myaccount/api/v1/cdn/monitoring-data/?apikey={{apikey}}&location={{location}}&start_date={{start_date}}&end_date={{end_date}}&distribution_id={{distribution_id}}&granularity={{granularity}}}&project_id={{project-id}}

import http.client

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = ''
headers = {
        'Authorization': 'Bearer '
    }
conn.request("GET", "/myaccount/api/v1/cdn/monitoring-data/?apikey={{api_key}}&location=Delhi&start_date=2022-05-04&end_date=2022-05-19&distribution_id={{distribution_id}}&granularity=daily&project_id={{project-id}}", payload, headers)
res = conn.getresponse()
  data = res.read()
print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
    "code": 200,
    "data": [],
    "errors": {},
    "message": "Success"
}

CDN Bandwidth Usages

To View CDN Bandwidth Usage, send a Post request :-

https://api.e2enetworks.com/myaccount/api/v1/cdn/domain-usage/?apikey={{apikey}}&project_id={{project-id}}

import http.client
import json

conn = http.client.HTTPSConnection("api.e2enetworks.com")
payload = json.dumps({
"domain": "all",
"end_date": "2022-05-19",
"granularity": "daily",
"start_date": "2022-05-04"
})
headers = {
  'Authorization': 'api_token',
    'Content-Type': 'application/json',
}
conn.request("POST", "/myaccount/api/v1/cdn/domain-usage/?apikey={{api_key}}&project_id={{project-id}}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAi...
{
  "domain": "all",
  "end_date": "2022-05-19",
  "granularity": "daily",
  "start_date": "2022-05-04"
}