API Beginners Guide

The Snapt API is an XmlRpc API to all of the Snapt modules and functions. You can retrieve statistics, issue commands, change configurations and much more with correct use of the API. For detailed commands for the various modules please go to their specific sections.

 

Installation

In order to use the Snapt API you must install the Snapt API plugin (freely available) via the Plugin system on the server. You can then go to the Setup -> API menu in order to receive your API Key and Secret Key for interacting with the API. These keys will be required in every API command to authenticate you.

 

Starting Out

We advise you select either the PHP, Ruby or Python example code library to build on top of. These are available on the Code page.

 

Sending Commands

The Snapt API works on a per-module basis. The module you want to interact with may be the Balancer or Accelerator, or others. You must indicate this on the URL string, as well as in your command.

For example, this is the URL we send an XMLRPC request to in order to speak to the Balancer:

This string is made up of 4 parts. The first is the URL to the API: http://snapt:8080/api/. The second is the API Key given to you, and the third is the API secret given to you. The final part (snaptHA) is the module. These are the module names for the available APIs:

  • Balancer: snaptHA
  • Accelerator: snaptNginx
  • WAF: snaptWAF
  • Cache: snaptSquid
  • Backup: snaptBackup
  • GSLB: snaptGSLB
  • Redundancy: snaptRed

There are several framework APIs available as well:

  • Operating System: os
  • Activity Log: act
  • Notices: notices

 

Your First Command

For our first command we will request a list of the methods available in the “os” class. In order to do that we use the built in request “system.listMethods” which is available in every module.

As you can see we are referencing the os API, and sending system.listMethods() in Python. This returns the following:

Let us try the os.getIPs request, to receive a list of the IP addresses on the server.

Here you can see we have changed our request to os.getIPs(). This could be any of the commands above.  It returns the following information for us:

And that is how you send a command and receive information – congratulations! You can use the system.listMethods command to explode and discover commands as well. As you can see, getCPUUsage would return CPU Usage and so on.

 

Advanced Commands

As your API usage grows you will need to send information as well – parameters for your request. These are passed as parameters to your calls. Below you will see an example of sending a “stat” request to socketGet in the Balancer. This returns us a dump of the live stats from the Balancer socket:

The results look like so:

If we were to change that to “info” instead of “stat” we would receive this: