PHPackages                             reashetyr/namecheap - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. reashetyr/namecheap

ActiveLibrary

reashetyr/namecheap
===================

Easy access to the Namecheap xml api using PHP

v0.5.1(5y ago)3321MITPHPPHP &gt;=7

Since Nov 6Pushed 5y ago2 watchersCompare

[ Source](https://github.com/reashetyrr/namecheap-php)[ Packagist](https://packagist.org/packages/reashetyr/namecheap)[ RSS](/packages/reashetyr-namecheap/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (1)Versions (7)Used By (0)

Namecheap API for PHP
=====================

[](#namecheap-api-for-php)

THIS IS STILL IN VERY BETA DO NOT USE YET!

namecheap-php is a Namecheap API client in PHP. API itself is documented at

This client supports:

- Registering a domain
- Checking domain name availability
- Listing domains you have registered
- Getting contact information for a domain
- Setting DNS info to default values
- Set DNS host records

### Installation

[](#installation)

Installation is as simple as:

```
composer require reashetyr/namecheap

```

### How to sign up to start using the API

[](#how-to-sign-up-to-start-using-the-api)

The API has two environments, production and sandbox. Since this API will spend real money when registering domains, start with the sandbox by going to  and creating an account. Accounts between production and sandbox are different, so even if you already have a Namecheap account you will need a new one.

After you have an account, go to "Profile".

[![Profile](img/profile.png "Profile")](img/profile.png)

From there, select the "Profile" menu again, then "Tools". Scroll to the bottom of the page to the "Business &amp; Dev Tools" and select "Manage" on the "Namecheap API Access" section.

[![API menu](img/apimenu.png "API menu")](img/apimenu.png)

You'll get to your credentials page. From here you need to take note of your api key, username and add your IP to the whitelist of IP addresses that are allowed to access the account. You can check your public IP by searching "what is my ip" on Google and add it here. It might take some time before it actually starts working, so don't panic if API access doesn't work at first.

[![Credentials](img/credentials.png "Credentials")](img/credentials.png)

### How to access the API from PHP

[](#how-to-access-the-api-from-php)

Install the package using composer. You can access the API as follows:

```
use reashetyr\NameCheap\NameCheap;
$api = new NameCheap(username, api_key, username, ip_address, true);

```

The fields are the ones which appear in the credentials screen above. The username appears twice, because you might be acting on behalf of someone else.

### Registering a domain name using the API

[](#registering-a-domain-name-using-the-api)

Unfortunately you need a bunch of contact details to register a domain, so it is not as easy as just providing the domain name. In the sandbox, the following contact details are acceptable. Trickiest field is the phone number, which has to be formatted as shown.

```
NameCheap.domains_create([
    'DomainName' => 'registeringadomainthroughtheapiwow.com',
    'FirstName' => 'Jack',
    'LastName' => 'Trotter',
    'Address1' => 'Ridiculously Big Mansion, Yellow Brick Road',
    'City' => 'Tokushima',
    'StateProvince' => 'Tokushima',
    'PostalCode' => '771-0144',
    'Country' => 'Japan',
    'Phone' => '+81.123123123',
    'EmailAddress' => 'jack.trotter@example.com'
]);

```

This call should succeed in the sandbox, but if you use the API to check whether this domain is available after registering it, the availability will not change. This is normal.

### How to check if a domain name is available

[](#how-to-check-if-a-domain-name-is-available)

The domains\_check method returns True if the domain is available.

```
NameCheap.domains_check(domain_name);

```

You can also pass a list of domain names, in which case it does a batch check for all and returns an array of the answers. You should probably not be writing a mass domain checking tool using this, it is intended to be used before registering a domain.

### Basic host records management code

[](#basic-host-records-management-code)

Here's the example of simple DNS records management script:

```
