API

From CPanelDirect
Jump to: navigation, search

cPanelDirect offers a SOAP based API to list, buy and cancel licenses. Our SOAP url is at https://cpaneldirect.net/api.php which also lists the API commands.

A full PHP example is at https://cpaneldirect.net/soapclient.phps

License Types

The license types are passed with in the soap buy function. For example $response = $client->api_buy_license($session, '4.2.2.2', 1, ) is passing license type 1. The format is IP, License Type, Coupon.

*       ID      Cost    License Name
*       4       $4      Fantastico
*       7       $5      Softaculous
*       8       $4      Softaculous VPS
*       14      $4      Fantastico VPS
*       1       $36     INTERSERVER-EXTERNAL (Full External license)
*       2       $15     INTERSERVER-EXTERNAL-VPS (Other VPS types besides OpenVZ/Virtuozzo)
*       3       $14     INTERSERVER-EXTERNAL-VZZO (OpenVZ/Virtuozzo)
*       6       $55     INTERSERVER-ENKOMP-EXTERNAL-A500 (Windows Enkompass)

Internal License ips only work on IP blocks owned by interserver. An order for non-interserver ips will fail.

*       9       $20     INTERSERVER-INTERNAL
*       15      $10     INTERSERVER-INTERNAL-VPS
*       10      $10     INTERSERVER-INTERNAL-VZZO


Below are some examples that can be used with the API.

Example BUY License

Notice the below have make_payment api call in them. This uses a credit card or pre-pay. If you are paying by paypal use the api_get_paypal_url option to return the paypal payment url.

Remember in api_buy_license the format is IP, License Type, Coupon.

PHP SOAP Example

$client = new SoapClient("https://cpaneldirect.net/api.php?wsdl");
$session = $client->api_login($username, $password);
$response = $client->api_buy_license($session, '4.2.2.2', 1, '')
if ($response->status == 'ok')
{
     echo "License Ordered";
     $payment_response = $client->make_payment($session, 'licenses', $response->invoice);
     if ($payment_response->status == 'ok')
          echo "Payment Completed";
     else
          echo "Payment Problem " . $payment_response->status_text;
}
else
     echo "Ordering Problem " . $response->status_text;

Perl SOAP Example

#!/usr/bin/perl -w
use SOAP::Lite;

my $soap = SOAP::Lite->uri('urn:myapi')->proxy('https://cpaneldirect.net/api.php');
my $username = 'username';
my $password = 'password';
my $ip = '4.2.2.2';
my $license_type = 1;
my $coupon = '';
my $sid = $soap->api_login($username, $password)->result();
my $result = $soap->api_buy_license($sid, $ip, $license_type, $coupon)->result();
$soap->api_make_payment($sid, 'licenses', $result->invoice);

Example PAY License

This requires automatic credit card payments on the account, or a pre-pay

echo "Test of api_make_payment($sid, 'licenses', $return->invoice)\n";
$payment_return = $client->api_make_payment($sid, 'licenses', $return->invoice);
echo "    Status: $payment_return->status\n";
echo "    Status Text: $payment_return->status_text\n";
echo "\n";

Please note the above buy license examples include the api_make_payment. By not submitting api_make_payment the license order is placed but is in a pending state.

Paypal Link

If you prefer paypal, you may follow this format to return a payment link

$sid = $client->api_login($username, $password);
echo "    Session ID: $sid\n\n";

echo "Test of api_get_paypal_url('licenses', 9)\n";
/* Sample Output
 *
 *  <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal@cpaneldirect.net&item_name=%28Repeat+Invoice%3A+15%29+INTERSERVER-EXTERNAL&custom=INVlicenses9&buyer_credit_promo_code=&buyer_credit_product_category=&buyer_credit_shipping_method=&buyer_credit_user_address_change=&amount=40.00&no_shipping=0&no_note=1&currency_code=USD&lc=US&bn=PP%2dBuyNowBF&charset=UTF%2d8" target=_blank>Click Here to make a PayPal payment</a>
 */
echo "    " . $client->api_get_paypal_url('licenses', 9) . "\n\n";

Cancel License

PHP example of cancel license

<?php

$username = 'email@email.com';
$password = 'secret';
$client = new SoapClient("https://cpaneldirect.net/api.php?wsdl");
$sid = $client->api_login($username, $password);
// 312312 = license id
$return = $client->api_cancel_license($sid, 312312);
if ($return->status == 'error')
{
        echo 'ERROR: ' . $return->status_text;
}
else
{
        // success
        echo $return->status_text;
}
?>

or

<?php

$username = 'email@email.com';
$password = 'secret';
$client = new SoapClient("https://cpaneldirect.net/api.php?wsdl");
$sid = $client->api_login($username, $password);
// api_cancel_license_ip($sid, $ip);
// 1 is license type
$return = $client->api_cancel_license_ip($sid, '1.2.3.4');
if ($return->status == 'error')
{
        echo 'ERROR: ' . $return->status_text;
}
else
{
        // success
        echo $return->status_text;
}
?>


Change IP

$api->change_license_ip($sid, $oldip, $newip);

<?php

$username = 'email@email.com';
$password = 'secret';
$client = new SoapClient("https://cpaneldirect.net/api.php?wsdl");
$sid = $client->api_login($username, $password);
$return = $client->api_change_license_ip($sid, '1.2.3.4', '4.3.2.1');
if ($return->status == 'error')
{
    echo 'ERROR: ' . $return->status_text;
}
else
{
    // success
    echo $return->status_text;
}
?>

You can also change the IP based on the ID

 $api->change_license_ip_by_id($sid, $id, $newip)       function now

Where $id is the license ID

Get a list of unpaid invoices

Sample Code downloadable at https://cpaneldirect.net/api_samples/api_licenses_get_client_unpaid_invoices.phps

<?php

   $client = new SoapClient("https://my.interserver.net/api.php?wsdl");
   $session_id = $client->api_login('username@site.com', 'password');
   $invoices = $client->api_licenses_get_client_unpaid_invoices($session_id);
echo '';
   if (sizeof($invoices) == 0)
echo '';
   else
       foreach ($invoices as $invoice)
echo ''; echo '
IDDescriptionAmountDue Date
No Invoices'.$invoice->invoices_id.''.$invoice->invoices_description.'' .$invoice->invoices_amount.''.$invoice->invoices_due_date.'
';

?>


Sample Output

ID Description Amount Due Date 509444 (Repeat Invoice: 389636) INTERSERVER-EXTERNAL 34.95 2013-09-01 19:47:33 509445 (Repeat Invoice: 389637) Fantastico 4 2013-09-01 19:49:15