PHP code example of level23 / dynadot-api

1. Go to this page and download the library: Download level23/dynadot-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/ */

    

level23 / dynadot-api example snippets



use Level23\Dynadot\Client;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    $domainInfo = $client->getDomainInfo('example.com');
    
    // process your domain info here
    print_r($domainInfo);
} catch (Exception $e) {
    // ... handle exception
}



use Level23\Dynadot\Client;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    $domainList = $client->getDomainList();

    foreach ($domainList->domains as $domain) {
        echo $domain->domainName . "\n";
        echo $domain->expiration . "\n";
    }
} catch (Exception $e) {
    // ... handle exception
}



use Level23\Dynadot\Client;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    $result = $client->setNameservers('example.com', ['ns01.example.com', 'ns2.example.net', 'ns03.example.org']);
    // ...
} catch (Exception $e) {
    // ... handle exception
}


use Level23\Dynadot\Client;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    $contact = $client->getContactInfo(1234); // 1234 = the contact id
    print_r($contact);
} catch (Exception $e) {
    echo $e->getMessage();
}


use Level23\Dynadot\Client;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    $contactList = $client->getContactList();
    
    foreach ($contactList->contacts as $contact) {
        echo "Contact ID: " . $contact->contactId . "\n";
        echo "Name: " . $contact->name . "\n";
        echo "Email: " . $contact->email . "\n";
        echo "---\n";
    }
} catch (Exception $e) {
    echo $e->getMessage();
}



use Level23\Dynadot\Client;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    $result = $client->setRenewOption('example.com', 'auto');
    // ...
} catch (Exception $e) {
    // ... handle exception
}



use Level23\Dynadot\Client;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    $result = $client->search('example.com', true, 'USD');
    
    echo "Domain: " . $result->domainName . "\n";
    echo "Available: " . ($result->available ? 'Yes' : 'No') . "\n";
    if ($result->available && isset($result->price)) {
        echo "Price: $" . $result->price . "\n";
    }
} catch (Exception $e) {
    // ... handle exception
}



use Level23\Dynadot\Client;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    $domains = ['example.com', 'test.org', 'mydomain.net'];
    $result = $client->bulkSearch($domains);
    
    foreach ($result->domainResults as $domainResult) {
        echo "Domain: " . $domainResult->domainName . "\n";
        echo "Available: " . ($domainResult->available ? 'Yes' : 'No') . "\n";
        echo "---\n";
    }
} catch (Exception $e) {
    // ... handle exception
}



use Level23\Dynadot\Client;
use Level23\Dynadot\Dto\Contact;
use Level23\Dynadot\Dto\DomainRegistrationRequest;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    
    // Create contact information
    $registrantContact = Contact::create(
        organization: 'Example Corp',
        name: 'John Doe',
        email: '[email protected]',
        phoneNumber: '1234567890',
        phoneCc: '1',
        address1: '123 Main St',
        city: 'New York',
        state: 'NY',
        zip: '10001',
        country: 'US',
    );

    // Create domain registration request
    $registrationData = DomainRegistrationRequest::create(
        duration: 1,
        authCode: '',
        customerId: 0,
        registrant: $registrantContact,
        admin: $registrantContact,
        tech: $registrantContact,
        billing: $registrantContact,
        nameserverList: ['ns1.example.com', 'ns2.example.com'],
        privacy: 'true',
        currency: 'USD',
        registerPremium: false,
        couponCode: '',
    );

    // Register the domain
    $result = $client->registerDomain('example.com', $registrationData);
    
    echo "Domain registration successful!\n";
    echo "Domain: " . $result->domainName . "\n";
    echo "Expiration Date: " . date('Y-m-d H:i:s', $result->expirationDate) . "\n";
} catch (Exception $e) {
    // ... handle exception
}


use Level23\Dynadot\Client;

$apiKey = 'xxx YOUR API KEY xxx';
$apiSecret = 'xxx YOUR API SECRET xxx';

try {
    $client = new Client($apiKey, $apiSecret);
    $accountInfo = $client->getAccountInfo();
    print_r($accountInfo);
} catch (Exception $e) {
    echo $e->getMessage();
}