1. Go to this page and download the library: Download dsolodev/namecheap-sdk 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/ */
dsolodev / namecheap-sdk example snippets
declare(strict_types=1);
use Namecheap\ApiClient;
use Namecheap\Services\DomainService;
use Namecheap\Services\SslService;
use Namecheap\Services\UserService;
use Namecheap\Response\NamecheapResponse;
// Create API client
$apiClient = new ApiClient(
apiUser: 'your_api_user',
apiKey: 'your_api_key',
userName: 'your_username',
clientIp: '192.168.1.100'
);
// Enable sandbox for testing (optional)
$apiClient->enableSandbox();
// Domain management with structured response
$domainService = new DomainService($apiClient);
$response = $domainService->getList();
if ($response->isSuccess()) {
$domains = $response->getData();
echo "Found " . count($domains) . " domains\n";
} else {
foreach ($response->getErrors() as $error) {
echo "Error: $error\n";
}
}
// SSL certificate management
$sslService = new SslService($apiClient);
$sslResponse = $sslService->getList();
// Access data easily
$certificates = $sslResponse->getData();
$executionTime = $sslResponse->getExecutionTime();
use Namecheap\Services\DomainDnsService;
$dnsService = new DomainDnsService($apiClient);
// Get DNS hosts
$hosts = $dnsService->getHosts('example.com');
// Set DNS hosts
$result = $dnsService->setHosts('example.com', $hostRecords);
// Get email forwarding
$forwarding = $dnsService->getEmailForwarding('example.com');
use Namecheap\Services\SslService;
$sslService = new SslService($apiClient);
// Get SSL certificates
$certificates = $sslService->getList();
// Create SSL certificate
$result = $sslService->create($certificateInfo);
// Activate SSL certificate
$result = $sslService->activate($certificateId, $activationInfo);
use Namecheap\Services\UserService;
$userService = new UserService($apiClient);
// Get account balances
$balances = $userService->getBalances();
// Get pricing information
$pricing = $userService->getPricing();
// Update user information
$result = $userService->update($userInfo);
// Old way (v0.x)
$api = new Namecheap\Api($credentials);
$domains = $api->domains()->getList();
// New way (v1.0+)
$apiClient = new ApiClient($credentials);
$domainService = new \Namecheap\Services\DomainService($apiClient);
$domains = $domainService->getList();
// Enable sandbox mode for testing
$apiClient->enableSandbox();
// Your test code here...
// Disable sandbox mode
$apiClient->disableSandbox();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.