PHP code example of balfour / domains-coza-api

1. Go to this page and download the library: Download balfour/domains-coza-api 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/ */

    

balfour / domains-coza-api example snippets


use GuzzleHttp\Client as Guzzle;
use Balfour\DomainsResellerAPI\Client;

$guzzle = new Guzzle();
$client = new Client($guzzle, 'your-api-key');

$response = $client->registerDomain(
    'mydomain.co.za',
    'Balfour Group (Pty) Ltd',
    '[email protected]',
    '+27.211111111',
    'My Address Line 1',
    'My Optional Address Line 2',
    '8001',
    'ZA',
    'Balfour Group (Pty) Ltd',
    'Cape Town',
    'Western Cape',
    1, // years - max of 1 year for co.za domains
    true, // use managed nameservers
    [],
    'TEST1' // optional external ref
);

// using custom nameservers
$response = $client->registerDomain(
    'mydomain.co.za',
    'Balfour Group (Pty) Ltd',
    '[email protected]',
    '+27.211111111',
    'My Address Line 1',
    'My Optional Address Line 2',
    '8001',
    'ZA',
    'Balfour Group (Pty) Ltd',
    'Cape Town',
    'Western Cape',
    1, // years - max of 1 year for co.za domains
    false, // not using managed nameservers
    [
        'ns1.foo.bar',
        'ns2.foo.bar',
        'ns3.foo.bar',
        'ns4.foo.bar',
        'ns5.foo.bar',
    ],
    'TEST1' // optional external ref
);

// you can also register a domain using an implementation of RegistrantInterface
// eg: assuming $registrant is an implementation
$response = $client->registerDomainForRegistrant('mydomain.co.za', $registrant);

$isAvailable = $client->isDomainAvailable('mydomain.co.za');

$response = $client->deleteDomain('mydomain.co.za');

$response = $client->updateDomainRegistrant(
    'mydomain.co.za',
    'Balfour Group (Pty) Ltd',
    '[email protected]',
    '+27.211111111',
    'My Address Line 1',
    'My Optional Address Line 2',
    '8001',
    'ZA',
    'Balfour Group (Pty) Ltd',
    'Cape Town',
    'Western Cape'
);

// you can also use an implementation of RegistrantInterface
$client->updateDomainRegistrantFromRegistrant('mydomain.co.za', $registrant);

$response = $client->renewDomain('mydomain.co.za', 1);

$response = $client->transferDomain(
    'mydomain.co.za',
    'Balfour Group (Pty) Ltd',
    '[email protected]',
    '+27.211111111',
    'My Address Line 1',
    'My Optional Address Line 2',
    '8001',
    'ZA',
    'Balfour Group (Pty) Ltd',
    'Cape Town',
    'Western Cape',
    null, // epp key (if ,
    null, // epp key (if 

$response = $client->suspendDomain('mydomain.co.za');

$response = $client->unsuspendDomain('mydomain.co.za');

$response = $client->checkMultipleTLDAvailability('mydomain');
var_dump($response->getTLDs());
var_dump($response->getAvailableTLDs());
var_dump($response->getAvailableTLDs());
var_dump($response->getTakenTLDs());
var_dump($response->getTLD('co.za'));
var_dump($response->isTLDAvailable('co.za'));

$response = $client->getDomain('mydomain.co.za');

$contacts = $response->getContacts();
var_dump($contacts);

$registrant = $response->getRegistrant();
var_dump($registrant->getContactNumber());
var_dump($registrant->hasPendingUpdate());
var_dump($registrant->getPendingUpdate()->getExpectedChangeDate());

var_dump($response->getNameservers());

var_dump($response->getCreationDate());

// use managed dns
$response = $client->updateNameservers('mydomain.co.za', true);

// use custom nameservers
$response = $client->updateNameservers(
    'mydomain.co.za',
    false,
    [
        'ns1.foo.bar',
        'ns2.foo.bar',
        'ns3.foo.bar',
        'ns4.foo.bar',
        'ns5.foo.bar',
    ]
);

$response = $client->getDomainEPPAuthKey('mydomain.co.za');
var_dump($response->getEPPKey());

$response = $client->cancelDomainUpdate('mydomain.co.za');

$response = $client->cancelDomainDelete('mydomain.co.za');

$response = $client->setDomainAutoRenew('mydomain.co.za', true);
$response = $client->setDomainAutoRenew('mydomain.co.za', false);
$response = $client->enableDomainAutoRenew('mydomain.co.za');
$response = $client->disableDomainAutoRenew('mydomain.co.za');

$response = $client->checkDomainTransfer('mydomain.co.za');
var_dump($response->getRequestDate());
var_dump($response->getStatus());
var_dump($response->isComplete());

$response = $client->cancelDomainTransfer('mydomain.co.za');

$response = $client->getDomainTotalsSummary();
var_dump($response->getSummary());
var_dump($response->getTotalTransfersIn());

$response = $client->getDomains();

// using limit and offset
$response = $client->getDomains(15, 0);

// sorting results
$response = $client->getDomains(15, 0, 'dateRegistered');
$response = $client->getDomains(15, 0, 'dateRegistered', 'descending');

// filtering results
$response = $client->getDomains(15, 0, 'name', 'ascending', 'expiring90');

var_dump($response->getTotal());

foreach ($response->getDomains() as $domain) {
    var_dump($domain->getName());
    var_dump($domain->isPremiumDNSEnabled());
    var_dump($domain->getCreationDate());
    var_dump($domain->getNameservers());
}

$response = $client->searchDomains('mydomain');

foreach ($response->getDomains() as $domain) {
    var_dump($domain->getName());
    var_dump($domain->getStatus());
}

use Badcow\DNS\AlignedBuilder;

$response = $client->getDNSRecords('mydomain.co.za');

var_dump($response->toArray());

foreach ($response->getRecords() as $record) {
    var_dump($record->getType());
    var_dump($record->getName());
    var_dump($record->getContent());
    var_dump($record->getPriority()); // only applicable to MX records
    var_dump($record->getTTL());
}

// filter by type of record
$records = $response->getRecordsByType('MX');

// the records can be formatted as a zone file
$zone = $response->getZone();
echo AlignedBuilder::build($zone);

use Badcow\DNS\Rdata\Factory;
use Badcow\DNS\ResourceRecord;

// this example assumes no existing records
$a = new ResourceRecord;
$a->setName('sub.domain');
$a->setTtl(3600);
$a->setRdata(Factory::A('127.0.0.1'));

$mx = new ResourceRecord();
$mx->setName('@');
$mx->setRdata(Factory::Mx(10, 'mail-gw1.example.net.'));

$response = $client->updateDNSRecords('mydomain.co.za', [$a, $mx]);

// here, we first fetch the existing records, add a new record to the zone, then update passing in the zone
$response = $client->getDNSRecords('mydomain.co.za');
$zone = $response->getZone();

$a = new ResourceRecord;
$a->setName('sub.domain');
$a->setTtl(3600);
$a->setRdata(Factory::A('127.0.0.1'));

$zone->addResourceRecord($a);

// notice how we're just passing in a 
$client->updateDNSRecordsFromZone($zone);

// you can also update the records from a local zone file
$client->updateDNSRecordsFromZoneFile('mydomain.co.za', '/path/to/zonefile');