PHP code example of heximcz / api-wrapper-webglobe

1. Go to this page and download the library: Download heximcz/api-wrapper-webglobe library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

heximcz / api-wrapper-webglobe example snippets


use Webglobe\ApiWebglobe;
use Webglobe\Exceptions\ApiWebglobeException;
use Webglobe\Exceptions\ApiWebglobeResponseException;

$production = false; 
$login = "login";
$password = "password";

try {
    // URL
    $api_url = "https://api." . ($production ? "" : "staging.") . "webglobe.com";

    $api = new ApiWebglobe($api_url, $login, $password);

    // get domain info
    $api->domainInfoByName("example.com");

    var_dump($api->getResponse());

} catch (ApiWebglobeException $e) {
    // CURL or JSON decode errors
    if (isset($api)) {
        var_dump($api->getResponse());
        var_dump($api->getReturnCode());
    }
    echo "API error occurred: " . $e->getMessage();
} catch (ApiWebglobeResponseException $e) {
    // Handle response errors (return code >= 400)
    if (isset($api)) {
        var_dump($api->getResponse());
        var_dump($api->getReturnCode());
    }
    echo "API error occurred: " . $e->getMessage();
}


use Webglobe\ApiWebglobe;
use Webglobe\Exceptions\ApiWebglobeException;
use Webglobe\Exceptions\ApiWebglobeResponseException;
use Webglobe\Payloads\Contact;

$production = false; 
$login = "login";
$password = "password";

try {
    // URL
    $api_url = "https://api." . ($production ? "" : "staging.") . "webglobe.com";

    $api = new ApiWebglobe($api_url, $login, $password);

    // Prepare payload for contact data
    // in this case is used 'FO'
    $contact = new Contact();
    $contact->setAction("create")
        ->setSingleTld("cz")
        ->setLegalForm("FO")
        ->setStreet("Street 1")
        ->setTown("City")
        ->setPostcode("11150")
        ->setCountry("CZ")
        ->setEmail("[email protected]")
        ->setContactName("John Doe")
        ->setLang("cs")
        ;

    // echo $contact->toJson();
    // var_dump($contact->toArray());
    // die;

    $api->contactCreate($contact->toArray());

    // show response
    var_dump($api->getResponse());

    // Get info about new crated contact
    $contact_create_response = $api->getResponse();
    if ($contact_create_response["success"]){
        $api->contactDetailById($contact_create_response["contact_id"]);

        // show response
        var_dump($api->getResponse());
    }

} catch (ApiWebglobeException $e) {
    // CURL or JSON decode errors
    if (isset($api)) {
        var_dump($api->getResponse());
        var_dump($api->getReturnCode());
    }
    echo "API error occurred: " . $e->getMessage();
} catch (ApiWebglobeResponseException $e) {
    // Handle response errors (return code >= 400)
    if (isset($api)) {
        var_dump($api->getResponse());
        var_dump($api->getReturnCode());
    }
    echo "API error occurred: " . $e->getMessage();
}

$domain = "example.com";
$tld = "com";

// only "registration" method is implemented for now
$order = new Order("registration");

$order->setPaymentType("credit")
      ->setDomainName($domain)
      ->setPeriod(12)
      ->setIdRegistrant(<int>)
      ->setIdRegistrantAdmin(<int>)
      ;

switch ($tld) {
    case "cz":
        // NSSET ID for CZ domain:
        $order->setDnsType("G")
              ->setNssetId("<YOUR:NSSET-NAME-FOR-CZ>")
              ->setGroupId(<int>);
        break;
    default:
        // Nameservers group ID for other TLDs
        $order->setDnsType("G")
              ->setGroupId(<int>);
        break;
}

// show payload in json or array
echo $order->toJson();
var_dump($order->toArray());