Quick Start - API: Cyber Security

DescriptionQuick Start - API: Cyber Security

Contents



The API allows users to deal with many aspects of web application management - purge cache, create new web applications, manage an existing application - programmatically, without accessing the Control Center.

To start using the API you will need:

  1. Create the API application in the Control Center
  2. Receive the oAuth token
  3. Call any supported API

Creating the API application:

  1. Open the "Manage Company / API Application" page.


  2. Click "Add new application" and provide the desired name e.g: "Purge Cache for all web apps".


  3. Your new Client ID and Secret keys will be generated automatically. Click on the actual key value to see it fully expanded.

Receiving the oAuth token

To receive the oAuth token, simply send a POST request to https://security.leasewebcdn.com/api/oauth/token, supplying the Client ID and Secret keys you received during the new API creation. For example:

curl -F client_id=<Client ID>  -F client_secret=<Client Secret> -X POST https://security.leasewebcdn.com/api/oauth/token
 
Response:

{"access_token API_TOKEN", "token_type":"bearer", "expires_in":7200, "scope":"public"}

Calling any supported API

Call any API method using the oAuth token. For example:

Unix

curl 'https://security.leasewebcdn.com/api/v1/cache/purge?website_domain=somewebsite.cxx&website_resources=jpg' -X PUT -H 'Authorization: Bearer API_TOKEN'

Response:

{"status":"ok", "task_id":"63fe1e405b870132c0e23c15c2e26ba2"}


Ruby


#!ruby
require 'rest-client'
require 'json'
  
client_id = '8473...7c8d8' # your API application ID
client_secret = '6e846...8fc659' # your API application Secret
  
response = RestClient.post 'https://security.leasewebcdn/api/oauth/token', {
 grant_type: 'client_credentials',
 client_id: client_id,
 client_secret: client_secret
}
token = JSON.parse(response)['access_token']
  
puts RestClient.put 'https://security.leasewebcdn.com/api/v1/cache/purge_all',
 { webapp_domain: 'demo.example.com' },
 { 'Authorization' => "Bearer #{token}" }


Powershell

PARAM([Parameter(Mandatory=$True, Position = 0)][string]$client_id, #Specify API application id, API application secret, domain and resource
[Parameter(Mandatory=$True, Position = 1)][string]$client_secret,
[Parameter(Mandatory=$True, Position = 2)][string]$webappdomain,
[Parameter(Position = 3)][string]$webresource)
Try{
    $oauthUrl =  "https://security.leasewebcdn.com/api/oauth/token"     #URL from where we get oauth token
    $Body= 'client_secret={0}&grant_type=client_credentials&client_id={1}' -f $client_secret,$client_id
    $result = Invoke-RestMethod -URI $oauthUrl -Method Post -Body $Body     #Get the token
    $access_token = $result.access_token      #store token in $access_token
    write-host $webresource
    if([string]::IsNullOrEmpty($webresource))
    {
        $httpRequest = [System.Net.WebRequest]::Create("https://security.leasewebcdn.com/api/v1/cache/purge_all?webapp_domain="+$webappdomain)      #URL to purge all the cache
        $httpRequest.Method = "PUT"
        $httpRequest.Headers.Add("X_API_VERSION","1.5")
        $httpRequest.Headers.Add("Authorization","Bearer $access_token")
        [system.Net.WebResponse] $httpResponse = $httpRequest.GetResponse()
        $responseStream = $httpResponse.GetResponseStream()
        [System.IO.StreamReader] $streamReader = New-Object System.IO.Streamreader -ArgumentList $responseStream
        $httpResult = $streamReader.ReadToEnd()
        write-host $httpResult
    }
    if($webresource)
    {
        $httpRequest = [System.Net.WebRequest]::Create("https://security.leasewebcdn.com/api/v1/cache/purge?webapp_domain="+$webappdomain+"&webapp_resources="+$webresource)      #URL to purge the cache
        $httpRequest.Method = "PUT"
        $httpRequest.Headers.Add("X_API_VERSION","1.5")
        $httpRequest.Headers.Add("Authorization","Bearer $access_token")
        [system.Net.WebResponse] $httpResponse = $httpRequest.GetResponse()
        $responseStream = $httpResponse.GetResponseStream()
        [System.IO.StreamReader] $streamReader = New-Object System.IO.Streamreader -ArgumentList $responseStream
        $httpResult = $streamReader.ReadToEnd()
        write-host $httpResult
    }
}
catch
{
    [System.Exception] "Please check input"
}