PHP code example of kowap / namecheap-php

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

    

kowap / namecheap-php example snippets


use kowap\Namecheap\NamecheapClient;

$client = new NamecheapClient(
    apiUser:  'YOUR_API_USER',
    apiKey:   'YOUR_API_KEY',
    username: 'YOUR_USERNAME',
    clientIp: 'YOUR_IP',
    sandbox:  false
);

$balance = $client->users()->getBalance();

echo $balance->availableBalance;
echo $balance->currency;

$list = $client->domains()->getList([
    'Page'     => 1,
    'PageSize' => 100,
]);

foreach ($list->items as $item) {
    echo $item->domain . PHP_EOL;
}

DomainListResult {
    items: DomainListItem[]
    total: 53
    page: 1
    pageSize: 100
}

$result = $client->domains()->checkWithPrice('example.com');

echo $result->domain;
echo $result->available;
echo $result->price;

DomainCheckResult {
    domain: "example.com"
    available: true
    premium: false
    price: 11.28
    currency: "USD"
}

$domains = [
    'mytestdomain123.com',
    'supertest987.net',
    'helloexample.org'
];

$results = $client->domains()->checkManyWithPrice($domains);

foreach ($results as $r) {
    echo $r->domain . ' → ' . ($r->available ? 'Available' : 'Taken') . PHP_EOL;
}
bash
composer