Unofficial implementation for the Dynadot domain API
This library provides a PHP client for the Dynadot API, allowing you to manage domains, search for domain availability, and handle domain registrations programmatically.
Before you can use this API you have to:
- Get the API key and secret from the Dynadot backend
- Whitelist the IP address where your requests are coming from
By default, we will try to connect to the Dynadot API for 30 seconds. If that fails,
a GuzzleHttp\Exception\ConnectException
is thrown. You probably want to catch these in case if something goes wrong.
Install the latest version with:
$ composer require level23/dynadot-api
To make use of this API you have to run PHP 8.2 or higher.
If you want to help us improve this implementation, just contact us. All help is welcome! The only requirement for contributing is that all code is 100% covered by unit tests and that they implement the PSR standards.
See the file LICENSE for more information.
See CHANGELOG.md for a list of changes and version history.
See below some basic sample usages.
<?php
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
}
The returned object will be an instance of Level23\Dynadot\Dto\DomainListResult
containing domain information.
<?php
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
}
This will return a Level23\Dynadot\Dto\DomainListResult
object containing an array of domain objects. An exception will be
thrown when anything went wrong.
<?php
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
}
The setNameservers
method returns a NameserverUpdateResult
object. An exception will be thrown when something
went wrong.
<?php
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();
}
This returns a Level23\Dynadot\Dto\Contact
object with the contact details.
<?php
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();
}
<?php
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
}
The setRenewOption
lets you set the renewal setting for a domain. Values for the second
argument ($renewOption) can be "donot", "auto", "reset". The method returns a RenewOptionResult
object.
<?php
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
}
<?php
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
}
<?php
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: 'john.doe@example.com',
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
}
<?php
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();
}
This returns a Level23\Dynadot\Dto\AccountInfo
object with your account details.
The following methods are available in the Client
class:
getDomainInfo(string $domainName)
- Get detailed information about a specific domaingetDomainList()
- Get a list of all domains in your accountsetNameservers(string $domainName, array $nameservers)
- Set nameservers for a domaingetContactInfo(int $contactId)
- Get contact information by IDgetContactList()
- Get a list of all contacts in your accountsetRenewOption(string $domain, string $renewOption)
- Set renewal option for a domainsearch(string $domain, bool $showPrice = false, string $currency = 'USD')
- Search for domain availabilitybulkSearch(array $domains)
- Search for multiple domains at onceregisterDomain(string $domainName, DomainRegistrationRequest $registrationData)
- Register a new domaingetAccountInfo()
- Get information about the authenticated Dynadot account
The library throws specific exceptions for different error types:
Level23\Dynadot\Exception\ApiException
- When the API returns an error responseLevel23\Dynadot\Exception\NetworkException
- When there's a network communication errorLevel23\Dynadot\Exception\AuthenticationException
- When authentication failsLevel23\Dynadot\Exception\ValidationException
- When request validation failsLevel23\Dynadot\Exception\NotFoundException
- When a resource is not found
Make sure your IP address is whitelisted in the Dynadot backend. It can take a while (up to 1 hour) before the IP address is whitelisted.
The Dynadot API only allows 1 API call at the same time. It's not allowed to do concurrent API calls.
If you do request multiple API calls at the same time you can be banned. The ban will be for 10 to 15 minutes.
Information received via dynadot chat
The API Key is your public identifier, while the API Secret is used to sign your requests for authentication. Both are required for the API to work properly.