NetDNA / MaxCDN REST API Private Beta signup
Introduction
The NetDNA API[1] is an XML-RPC[2] based programming interface to many of the most common functions found in the NetDNA Control Panel.
The API includes important functions to create, and modify, prime and purge cache files, list and update users and create all of the various reports.
To use the NetDNA API, you must have a NetDNA account, an API Key, an API user id and the xmlrpc library installed. These are all described in more detail below along with complete documentation of all the API methods and their parameters. Sample scripts are included later in this document to make using the API as easy as possible.
Authentication
The functionality offered through the XML-RPC API requires NetDNA API user authentication.
Generate API Key and API User ID
In order to use the NetDNA Public API, developers must first generate a unique API Key and API User ID. To generate these, login to the NetDNA Control Panel, navigate to the Manage Account > API section and press the button labeled “Add API key” and a API Key and API User ID will be generated for you.
Request Parameters
All requests to the XML-RPC web services require authorization. Developers may gain access to the web services by generating an API Key and API User Id as detailed in the previous section. An apiUserId, authString and currentDate must be sent as a parameter with every XML-RPC method call.
- int apiUserId — A unique key required for each developer to access any XML-RPC method
- string authString — A unique authentication string required for each developer to access any XML-RPC method
- string currentDate — An ISO 8601 formatted date/time in America/Los Angeles time (PST/PDT), e.g. 2010-02-12T15:19:21-07:00
authString
An authString is a unique authentication string required for each developer to access any XML-RPC method call. It is an sha256 hash of the following string format:
currentDate:apiKey:method
Where:
- currentDate (string) — is an ISO 8601 formatted string of the current date/time in America/Los Angeles time (PST/PDT). This is based on PHP 5′s date(‘c’) output. Example: 2010-08-25T10:13:16-07:00
- apiKey (string) — is the API User Key generated through the control panel
- method (string) — is the XML-RPC method to invoke (without the namespace)
Note: Before getting the current date you will need to set your timezone to America/Los_Angeles. The API only executes calls with an authString generated within the last 10 minutes. You will see how to set the timezone in our sample codes section.
Sample authString generation code
$currentDate = date('c');
$apiKey = '1234asrx2sajsadedaxmisakaopqdfme';
$method = 'update';
$authString = hash('sha256', "$currentDate:$apiKey:$method");
Sample Code
To make it easy to get started, we have included sample API scripts.
PHP
<?php
date_default_timezone_set('America/Los_Angeles');
include("xmlrpc/lib/xmlrpc.inc");
$cur = date('c');
$apiKey = '1234ajfkepq23zxvmaoepflawqmxlawq';
$apiUserId = 199;
$namespace = 'cache';
$method = 'purge';
$authString = hash('sha256', $cur . ':' . $apiKey . ':' . $method);
// this is the url to purge
$url= 'http://zonename.alias.netdna-cdn.com/testing/test.png';
$f=new xmlrpcmsg("$namespace.$method", array(php_xmlrpc_encode($apiUserId),
php_xmlrpc_encode($authString), php_xmlrpc_encode($cur),
php_xmlrpc_encode($url)));
$c=new xmlrpc_client("/xmlrpc/cache", "api.netdna.com", 80,'http11');
$r=&$c->send($f);
print_r($r);
?>
You will need to have the xmlrpc library installed on your machine in order to use the API code with PHP. The xmlrpc include library is part of phpxmlrpc which is an open source package that can be downloaded fromhttp://sourceforge.net/projects/phpxmlrpc/files/phpxmlrpc/2.2.2/xmlrpc-2.2.2.tar.gz/download. The include library, xmlrpc.inc, is part of the package. Just extract the file and xmlrpc.inc will be located inside the lib folder.
Python
#! /usr/bin/python
from xmlrpclib import ServerProxy
from hashlib import sha256
from datetime import datetime, timedelta
apiKey = 'yourApiKeyHere'
apiUserId = 314159
def makePullzone(id, originUrl, domain):
global apiKey, apiUserId
from datetime import datetime
# Make sure pytz is installed: easy_install --upgrade pytz
from pytz import timezone
date = datetime.now(timezone('America/Los_Angeles')).replace(microsecond=0).isoformat()
# Thanks Cody @ Umbel for the fix!
authString = sha256(date + ":" + apiKey + ":create").hexdigest()
zoneInfo = {'name': id, 'origin': originUrl, 'vanity_domain': domain}
sp = ServerProxy('http://api.netdna.com/xmlrpc/pullzone')
return sp.pullzone.create(apiUserId, authString, date, zoneInfo)
print makePullzone('PullZoneId',
'http://your.server.goes.here',
'images.example.com')
ASP.NET
We are aware of an issues regarding the API “Date” being incorrect due to daylight savings time. We are not ASP experts so this code will need to be slightly tweaked but this solutions to make the code DST aware solved the issue for our customers:
If TimeZoneInfo.FindSystemTimeZoneById("Pacific StandardTime").IsDaylightSavingTime(DateTime.Now) Then
string APIDate = DateTime.UtcNow.AddHours(-8).ToString("yyyy-MM-ddThh:mm:ss")+"-07:00";
Else
string APIDate = DateTime.UtcNow.AddHours(-8).ToString("yyyy-MM-ddThh:mm:ss")+"-08:00";
End If
public class Ping
{
// The URL where the ping will be sent
// The URL where the ping will be sent
private string _PingUrl = "http://api.netdna.com/xmlrpc/cache";
public string PingUrl { get { return _PingUrl; } set { _PingUrl = value; } }
// Send the ping
public string Send()
{
try
{
int APIID = 199; //Replace this with your API Id
string APIKey = "1234ajfkepq23zxvmaoepflawqmxlawq"; //Replace this with your API Key
string APIDate = DateTime.UtcNow.AddHours(-8).ToString("yyyy-MM-ddThh:mm:ss")+"-08:00";
string APIMethod = "purgeAllCache"; //Replace this with your desired method
string authString = "";
string sSourceData;
byte[] tmpSource;
byte[] tmpHash;
sSourceData = APIDate + ":" + APIKey + ":" + APIMethod;
//Create a byte array from source data.
tmpSource = ASCIIEncoding.ASCII.GetBytes(sSourceData);
//Compute hash based on source data.
SHA256 shaM = new SHA256Managed();
tmpHash = shaM.ComputeHash(tmpSource);
authString = ByteArrayToString(tmpHash).ToLower();
// Build the ping
XmlRpcClientProtocol ClientProtocol;
iNetDNA netDNAProxy;
netDNAProxy = XmlRpcProxyGen.Create<iNetDNA>();
ClientProtocol = (XmlRpcClientProtocol)netDNAProxy;
ClientProtocol.Url = PingUrl;
Boolean response = netDNAProxy.purgeAllCache(APIID, authString, APIDate, "ZONE.ALIAS");
//Replace zone with your pull zone name and alias with your company alias name.
return response.ToString();
}
catch (Exception ex) {
return ex.ToString();
}
}
static string ByteArrayToString(byte[] arrInput)
{
int i;
StringBuilder sOutput = new StringBuilder(arrInput.Length);
for (i = 0; i < arrInput.Length; i++)
{
sOutput.Append(arrInput[i].ToString("X2"));
}
return sOutput.ToString();
}
}
public interface iNetDNA
{
[CookComputing.XmlRpc.XmlRpcMethod("cache.purge")]
Boolean purge(int apiUserId, string authString, string currentDate, string url);
[CookComputing.XmlRpc.XmlRpcMethod("cache.purgeAllCache")]
Boolean purgeAllCache(int apiUserId, string authString, string currentDate, string zone);
}
Data Types
Common Data Types
- array — Array of values, storing no keys
- base64 — base64 encoded binary data
- boolean — logical value (0 or 1)
- date/time — Date and time in ISO 8601 format
- double — double precision floating point number
- integer — Whole number, integer
- string — string of characters, must follow XML encoding
- struct — associative array
- nil — discriminative null value
Common Structs
1. struct pullzone (
- int id
- string name
- string origin
- string vhost
- string ip
- string compress
- string vanity_domain
- string vanity_ip
)
2. struct pushzone (
- int id
- string name
- string vanity_domain
- string vanity_ip
- string storage_location
)
3. struct vodzone (
- int id
- string name
- string storage_location
)
API Methods
List of all methods Here is a simple list of the available XML-RPC API methods. A complete description is included in the following sections.
Pull Zones
API URL
All XML-RPC requests should go to the following URL: http://api.netdna.com/xmlrpc/pullzone
pullzone.create
Description
pullzone.create – Creates a new Pull Zone on the edge servers. This type of zone caches content on the edge servers and pulls from the customer’s origin server as needed.
Method Signature
array pullzone.create ( int apiUserId, string authString, string currentDate, struct values )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- struct values– A pullzone struct
- string name
- string origin
- string vhost (optional)
- string ip (optional)
- string compress (optional)
- string vanity_domain (optional)
- string label (optional)
Return Values
On Success
array (0, struct ( * int '''id''' * string '''vanity_ip''' * string '''cdn_url''' ))
On Error
array ( int errorCode, string errorString )
- errorCode: 2001
- errorString: Pull Zone creation failed
- errorCode: 2002
- errorString: <name> is already in use
- errorCode: 2003
- errorString: <origin> does not resolve
pullzone.update
Description
pullzone.update – Updates an existing Pull Zone
Method Signature
int pullzone.update ( int apiUserId, string authString, string currentDate, int id, struct values )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- int id — the id of the zone to update
- struct values– A key/value pair that contains the new zone settings
- string name (optional)
- string origin (optional)
- string vhost (optional)
- string ip (optional)
- string compress (optional)
- string label (optional)
Return Values
Returns 0 if the update is a success, 1 if otherwise
pullzone.listZones
Description
pullzone.listZones – Lists all Pull Zones from an account
Method Signature
array pullzone.listZones ( int apiUserId, string authString, string currentDate )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
Return Values
An array of pullzones
Push Zones
API URL
All XML-RPC requests should go to the following URL: http://api.netdna.com/xmlrpc/pushzone
pushzone.create
Description
pushzone.create – Creates a new Push Zone.
Method Signature
array pushzone.create ( int apiUserId, string authString, string currentDate )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- struct values– a pushzone struct
- string name
- string password
- string compress (optional)
- string vanity_domain (optional)
- string label (optional)
Return Values
On Success
array (0, struct ( * int '''id''' * string '''vanity_ip''' * string '''storage_location''' * string '''cdn_url''' ))
On Error
array ( int errorCode, string errorMessage )
- errorCode: 3001
- errorString: Push Zone creation failed
- errorCode: 3002
- errorString: <name> is already in use
pushzone.update
Description
pushzone.update — Updates an existing Push Zone
Method Signature
int pushzone.update ( int apiUserId, string authString, string currentDate, struct values )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- int id — the id of the zone to update
- struct values
- string name (optional)
- string password (optional)
- string label (optional)
Return Values
Returns 0 if the update is a success, 1 if otherwise
pushzone.listZones
Description
pushzone.listZones — Lists all Push Zones from an account
Method Signature
array pushzone.listZones ( int apiUserId, string authString, string currentDate )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
Return Values
An array of pushzones
VOD Zones
API URL
All XML-RPC requests should go to the following URL: http://api.netdna.com/xmlrpc/vodzone
vodzone.create
Description
vodzone.create – Create a new VOD Zone.
Method Signature
array vodzone.create ( int apiUserId, string authString, string currentDate, struct values )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- struct values
- string name
- string password
- string label (optional)
Return Values
On Success
array (0, struct ( * int '''id''' * int '''vanity_ip''' * string '''storage_location''' ))
On Error
array ( int '''errorCode''', string '''errorMessage''' )
- errorCode: 4001
- errorString: VOD Zone creation failed
- errorCode: 4002
- errorString: <name> is already in use
vodzone.update
Description
vodzone.update — Updates an existing Vod Zone
Method Signature
int vodzone.update ( int apiUserId, string authString, string currentDate, int id, struct values )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- int id — the id of the zone to update
- struct values
- string name (optional)
- string password (optional)
- string label (optional)
Return Values
Returns 0 if the update is a success, 1 if otherwise
vodzone.listZones
Description
vodzone.listZones — Lists all Vod Zones from an account
Method Signature
array vodzone.listZones ( int apiUserId, string authString, string currentDate )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
Return Values
An array of vodzones
Live Zones
NOTE: The Live Zone API is available only by request. We can give access to the livezone api calls per api key.
API URL
All XML-RPC requests should go to the following URL: http://api.netdna.com/xmlrpc/livezone
livezone.create
Description
livezone.create – Create a new Live Zone.
Method Signature
array livezone.create ( int apiUserId, string authString, string currentDate, struct values )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- struct values
- string name
- string password
- string label (optional)
Return Values
On Success
array (0, struct ( * int '''id''' ))
On Error
array ( int '''errorCode''', string '''errorMessage''' )
- errorCode: 5001
- errorString: Live Zone creation failed
- errorCode: 5002
- errorString: <name> is already in use
livezone.update
Description
livezone.update — Updates an existing Live Zone
Method Signature
int livezone.update ( int apiUserId, string authString, string currentDate, int id, struct values )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- int id — the id of the zone to update
- struct values
- string name (optional)
- string password (optional)
- string label (optional)
Return Values
Returns 0 if the update is a success, 1 if otherwise
livezone.delete
Description
livezone.delete — Deletes an existing Live Zone
Method Signature
int livezone.delete ( int apiUserId, string authString, string currentDate, int id )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- int id — the id of the zone to delete
Return Values
Returns 0 if delete is a success, 1 if otherwise
livezone.listZones
Description
livezone.listZones — Lists all Live Zones from an account
Method Signature
array livezone.listZones ( int apiUserId, string authString, string currentDate )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
Return Values
An array of livezones
Cache
The methods to purge cache are listed in this section.
API URL
All XML-RPC requests should go to the following URL: http://api.netdna.com/xmlrpc/cache
cache.purge
Description
cache.purge – Purges a file from cache so it is pulled from the origin server the next time it is requested.
Method Signature
boolean cache.purge ( int apiUserId, string authString, string currentDate, string url )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- string url — url of the file to purge from cache
Return Values
Returns TRUE if purging is successful, FALSE if otherwise.
cache.purgeAllCache
Description
cache.purgeAllCache – Purges a file from cache so it is pulled from the origin server the next time it is requested.
Method Signature
boolean cache.purgeAllCache ( int apiUserId, string authString, string currentDate, string zone )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- string zone — The name of the zone to purge
Return Values
Returns TRUE if purging is successful, FALSE if otherwise.
User
API URL
All XML-RPC requests should go to the following URL: http://api.netdna.com/xmlrpc/user
user.listUsers
Description
user.listUsers – Lists all users on an account
Method Signature
array user.listUsers ( int apiUserId, string authString, string currentDate)
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
Return Values
Array of users
user.update
Description
user.update – Modifies user information
Method Signature
array user.update ( int userId, string authString, string currentDate, int id, struct values )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- int id — the id of the user to update
- struct values – The key/value pair for the new user settings
Return Values
array
Account
API URL
All XML-RPC requests should go to the following URL: http://api.netdna.com/xmlrpc/account
account.getBandwidth
Description
account.getBandwidth – Gets prepaid bandwidth remaining
Method Signature
array account.getBandwidth ( int apiUserId, string authString, string currentDate, string from, string to )
Parameters
- int apiUserId — the API user id
- string authString — used for server validation
- string currentDate — ISO 8601 formatted date
- string from — (optional) start date (Format: Y-m-d, Example: 2009-11-10)
- string to — (optional) end date (Format: Y-m-d, Example: 2010-11-10)
Return Values
The remaining prepaid bandwidth
Report
API URL
All XML-RPC requests should go to the following URL: http://api.netdna.com/xmlrpc/report
report.getTotalTransfer
Description
report.getTotalTransfer – Returns the total bandwidth transfer for a given Zone ID and date range
Method Signature
array report.getTotalTransfer ( int apiUserId, string authString, string currentDate, int zoneId, int type = null, string from = null, string to = null, string timezone = "GMT" )
Parameters
- int apiUserId
- string authString
- string currentDate
- int zoneId — the Zone ID
- int type — 1=today, 2=current hour, 3=date range
- string from — (optional if type=1 or type=2) starting date (Format: Y-m-d, Example: 2010-08-01)
- string to — (optional if type=1 or type=2) end date (Format: Y-m-d, Example: 2010-08-30)
- string timezone — (optional)
Return Values
array
report.getTotalHits
Description
report.getTotalHits – Get total hits for a given Zone ID and date range
Method Signature
int report.getTotalHits ( int apiUserId, string authString, string currentDate, int zoneId, int type = null, string from = null, string to = null, string timezone = "GMT" )
Parameters
- int apiUserId
- string authString
- string currentDate
- int zoneId — the Zone ID
- int type — 1=current date, 2=current hour, 3=date range
- string from — (optional if type=1 or type=2) start date (Format: Y-m-d, Example: 2010-08-01)
- string to — (optional if type=1 or type=2) end date (Format: Y-m-d, Example: 2010-08-30)
- string timezone — (optional)
Return Values
array
report.getTotalTransferStats
Description
report.getTotalTransferStats – Returns transfer stats for a given company/zone and date range
Method Signature
array report.getTotalTransferStats ( int apiUserId, string authString, string currentDate, mixed companyId, string dateFrom, string dateTo, int zoneId = NULL, array sortby = array(), string viewby = "daily", int maxReturn = NULL, string offset = NULL, string timezone = "GMT" )
Parameters
- int apiUserId
- string authString
- string currentDate
- mixed companyId — your unique company id or company alias
- string dateFrom — start date (Format: Y-m-d, Example: 2010-08-01)
- string dateTo — end date (Format: Y-m-d, Example: 2010-08-30)
- int zoneId — the Zone ID
- array sortby — (optional) an array of “column sortorder” strings, please see returned columns for possible values. sortorder can be ASC or DESC.
- string viewby — (optional) hourly or daily
- int maxReturn — (optional) the maximum number of records to return
- string offset — (optional) the offset of the first row to return, the first record is always 0
- string timezone — (optional)
Return Values
array
report.getCacheHitStats
Description
report.getCacheHits – Returns the total cache hits for a given company/zone and date range
Method Signature
int report.getCacheHitStats ( int apiUserId, string authString, string currentDate, mixed companyId, string dateFrom, string dateTo, int zoneId = NULL, array sortby = array(), int maxReturn = NULL, int offset = NULL, string timezone = "GMT" )
Parameters
- int apiUserId
- string authString
- string currentDate
- mixed companyId — your unique company id or company alias
- string dateFrom — start date
- string dateTo — end date
- int zoneId — the Zone ID
- array sortby — (optional) an array of “column sortorder” strings, please see returned columns for possible values. sortorder can be ASC or DESC.
- int maxReturn — (optional) the maximum number of records to return
- int offset — (optional) the offset of the first row to return, the first record is always 0
- string timezone — (optional)
Return Values
int
report.getPopularFiles
Description
array report.getPopularFiles – Returns a list of popular files for a given company/zone and date range
Method Signature
array report.getPopularFiles ( int apiUserId, string authString, string currentDate, mixed companyId, string dateFrom, string dateTo, int zoneId = NULL, array sortby = array('hits DESC'), int maxReturn = NULL, int offset = NULL )
Parameters
- int apiUserId
- string authString
- string currentDate
- mixed companyId — your unique company id or company alias
- string dateFrom — start date
- string dateTo — end date
- int zoneId — the Zone ID
- array sortby — (optional) an array of “column sortorder” strings, please see returned columns for possible values. sortorder can be ASC or DESC.
- int maxReturn — (optional) the maximum number of records to return
- int offset — (optional) the offset of the first row to return, the first record is always 0
Return Values
array
report.getUsagePerDay
Description
report.getUsagePerDay – Returns usage stats for a give company/zone and date range
Method Signature
int report.getUsagePerDay ( int apiUserId, string authString, string currentDate, mixed companyId, string dateFrom, string dateTo, int zoneId, array sortby = array(), int maxReturn = NULL, int offset = NULL )
Parameters
- int apiUserId
- string authString
- string currentDate
- mixed companyId — your unique company id or company alias
- string dateFrom — start date
- string dateTo — end date
- int zoneId — the Zone ID
- array sortby — (optional) an array of “column sortorder” strings, please see returned columns for possible values. sortorder can be ASC or DESC.
- int maxReturn — (optional) the maximum number of records to return
- int offset — (optional) the offset of the first row to return, the first record is always 0
Return Values
int
report.getNodeHits
Description
report.getNodeHits – returns a list of node hits for a given company/zone and date range
Method Signature
array report.getNodeHits ( int apiUserId, string authString, string currentDate, mixed companyId, string dateFrom, string dateTo, int zoneId = NULL, array sortby = array(), int maxReturn = NULL, int offset = NULL )
Parameters
- int apiUserId
- string authString
- string currentDate
- mixed companyId — your unique company id or company alias
- string dateFrom — start date
- string dateTo — end date
- int zoneId — the Zone ID
- array sortby — (optional) an array of “column sortorder” strings, please see returned columns for possible values. sortorder can be ASC or DESC.
- int maxReturn — (optional) the maximum number of records to return
- int offset — (optional) the offset of the first row to return, the first record is always 0
Return Values
array
report.getConnectionStats
Description
report.getConnectionStats – returns a list of live zone daily connection stats for a given company/zone and date range
Method Signature
array report.getConnectionStats ( int apiUserId, string authString, string currentDate, mixed companyId, string dateFrom, string dateTo, int zoneId = NULL, array sortby = array(), int maxReturn = NULL, int offset = NULL, string timezone = "GMT" )
Parameters
- int apiUserId
- string authString
- string currentDate
- mixed companyId — your unique company id or company alias
- string dateFrom — start date
- string dateTo — end date
- int zoneId — the Zone ID
- array sortby — (optional) an array of “column sortorder” strings, please see returned columns for possible values. sortorder can be ASC or DESC.
- int maxReturn — (optional) the maximum number of records to return
- int offset — (optional) the offset of the first row to return, the first record is always 0
- string timezone — (optional)
Return Values
array
report.getHourlyConnectionStats
Description
report.getHourlyConnectionStats – returns a list of live zone hourly connection stats for a given company/zone and date
Method Signature
array report.getHourlyConnectionStats ( int apiUserId, string authString, string currentDate, mixed companyId, string date, int zoneId = NULL, array sortby = array(), int maxReturn = NULL, int offset = NULL, string timezone = "GMT" )
Parameters
- int apiUserId
- string authString
- string currentDate
- mixed companyId — your unique company id or company alias
- string dateFrom — the date to fetch hourly stats from
- int zoneId — the Zone ID
- array sortby — (optional) an array of “column sortorder” strings, please see returned columns for possible values. sortorder can be ASC or DESC.
- int maxReturn — (optional) the maximum number of records to return
- int offset — (optional) the offset of the first row to return, the first record is always 0
- string timezone — (optional)
Return Values
array
Support