Page tree
Skip to end of metadata
Go to start of metadata

Introduction

The cPanelLicensing PHP class runs Manage2 API functions. You can use this to manage customer licenses from the command line or through the Manage2 user interface.

Important:

  • The cPanelLicensing PHP class requires PHP 5 with curl and SimpleXML support. PHP 5 enables SimpleXML support by default.
  • SimpleXML transforms XML into data structures that are similar to associative arrays.
  • The cPanelLicensing PHP class returns SimpleXML objects by default, or can return XML, JSON, or YAML.

For more information, read the SimpleXML documentation.

Download the module

To download the cPanelLicensing PHP class, click the cPanel License Management API SDK link in the Automation menu on the Manage2 Dashboard interface.

Basic use

The following script uses the cPanelLicensing PHP class to call the List License Information Manage2 API function:

// Include the cPanelLicensing class.
include("cpl.inc.php");
 
// Instantiate the cPanelLicensing object.
$cpl = new cPanelLicensing($USERNAME, $PASSWORD);

// Combine the parameters into an array.
$args = array("ip" => "192.168.1.1");
 
// Call the desired function with the parameters as an argument.
$cpl->fetchLicenses($args);

Include the cPanelLicensing class

// Include the cPanelLicensing class
include("cpl.inc.php");

Line 2 uses PHP's include() statement to include and evaluate the cPanelLicensing class.

Instantiate the cPanelLicensing object

// Instantiate the cPanelLicensing object.
$cpl = new cPanelLicensing(username, password);

Line 4 instantiates the cPanelLicensing object, which provides the script with access to the cPanelLicensing object's functions.

Note:

Include the following variables when you instantiate the cPanelLicensing object:

  • username — The user's username.
  • password — The user's password.

Call a function

// Combine the function's parameters into an array.
$args = array("ip" => "192.168.1.1");
 
// Call the Fetch License function.
$cpl->fetchLicenses($args);

Line 8 defines an array of the function's input parameters.

Line 11 calls the List License Information function and passes the array as an argument.

Note:

You can also perform this action in one step:

// Call the Fetch License function with the input parameters directly.
$cpl->fetchLicenses( array(
	"ip" => "192.168.1.1"
);

Methods

The cPanelLicensing PHP class includes the following methods:

The set_format() method

Use the set_format method to choose the PHP class's output type. By default, the class returns a SimpleXML object.

$cpl->set_format("json");

The set_format method accepts a single parameter with one of the following string values:

  • simplexml — Return SimpleXML.
  • xml — Return XML.
  • json — Return JSON.
  • yaml — Return YAML.

The findKey() method

Use the findKey method to retrieve a group or package name.

Note:

This method only operates in SimpleXML mode.

$packages = $cpl->fetchPackages();
$packageid = $cpl->findKey("ONE-YEAR", $packages);

This function accepts two parameters: search and package SimpleXML objects.