Package Exports
- @rqt/namecheap
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rqt/namecheap) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@rqt/namecheap
@rqt/namecheap is an implementation of the namecheap.com API.
yarn add -E @rqt/namecheapTable Of Contents
API
The package is available by importing its default function:
import NameCheap from '@rqt/namecheap'constructor(
options: Options,
): void
Create a new instance of the NameCheap class.
Options: Options for the NameCheap client.
| Name | Type | Description | Default |
|---|---|---|---|
| user* | string | The username required to access the API. | - |
| key* | string | The password required used to access the API. | - |
| ip* | string | The IP address of the client accessing the application (End-user IP address). | - |
| sandbox | boolean | Whether to use the sandbox version of the API. | false |
/* yarn example/ */
import NameCheap from '@rqt/namecheap'
import bosom from 'bosom'
(async () => {
try {
// 0. Create a client.
const { user, key, ip } = await bosom('.namecheap.json')
const namecheap = new NameCheap({
user, key, sandbox: true, ip,
})
// 1. Check a domain.
const c = await namecheap.domains.check('test.co')
console.log('Check:', c, '\n')
// 2. Get list of addresses on the account.
const cc = await namecheap.users.address.getList()
console.log('Addresses:', cc, '\n')
// 3. Find the default address and get its info.
const { AddressId } = cc.find(({ IsDefault }) => IsDefault)
const address = await namecheap.users.address.getInfo(AddressId)
// 4. Register the domain using the address.
const d = new Date().toLocaleString().replace(/[ :]/g, '-')
const domain = `rqt-example-${d}.com`
const r = await namecheap.domains.create({
domain,
address,
})
console.log('Registered:', r, '\n')
// 5. Retrieve info about domain.
const info = await namecheap.domains.getInfo(domain)
console.log('Info:', info, '\n')
// 6. Get a list of domains (with filter).
const list = await namecheap.domains.getList({
filter: domain,
})
console.log('List:', list, '\n')
} catch (err) {
console.log(err)
}
})()Check: [ { Domain: 'test.co',
Available: false,
ErrorNo: 0,
Description: '',
IsPremiumName: false,
PremiumRegistrationPrice: 0,
PremiumRenewalPrice: 0,
PremiumRestorePrice: 0,
PremiumTransferPrice: 0,
IcannFee: 0,
EapFee: '0.0' } ]
Addresses: [ { AddressId: 0,
AddressName: 'Primary Address',
IsDefault: false },
{ AddressId: 101235,
AddressName: 'Planet Express',
IsDefault: true } ]
Registered: { Domain: 'rqt-example-2018-10-5-18-05-29.com',
Registered: true,
ChargedAmount: '9.0600',
DomainID: 330569,
OrderID: 1293340,
TransactionID: 1830868,
WhoisguardEnable: true,
FreePositiveSSL: false,
NonRealTimeDomain: false }
Info: { Status: 'Ok',
ID: 330569,
DomainName: 'rqt-example-2018-10-5-18-05-29.com',
OwnerName: 'zavr',
IsOwner: true,
IsPremium: false,
DomainDetails:
{ CreatedDate: '10/05/2018',
ExpiredDate: '10/05/2019',
NumYears: 0 },
Whoisguard:
{ Enabled: 'True',
ID: 269098,
ExpiredDate: '10/05/2019',
EmailDetails:
{ WhoisGuardEmail: '67a07c27d9c24c0281c8da3bde63ac4c.protect@whoisguard.com',
ForwardedTo: 'zoidberg@futurama.bz',
LastAutoEmailChangeDate: '',
AutoEmailChangeFrequencyDays: 0 } },
PremiumDnsSubscription:
{ UseAutoRenew: false,
SubscriptionId: -1,
CreatedDate: 0000-12-31T21:00:00.000Z,
ExpirationDate: 0000-12-31T21:00:00.000Z,
IsActive: false },
DnsDetails:
{ ProviderType: 'FREE',
IsUsingOurDNS: true,
HostCount: 2,
EmailType: 'FWD',
DynamicDNSStatus: false,
IsFailover: false,
Nameserver: [ 'dns1.registrar-servers.com', 'dns2.registrar-servers.com' ] },
Modificationrights: { All: true } }
List: { domains:
[ { ID: 330569,
Name: 'rqt-example-2018-10-5-18-05-29.com',
User: 'zavr',
Created: '10/05/2018',
Expires: '10/05/2019',
IsExpired: false,
IsLocked: false,
AutoRenew: false,
WhoisGuard: 'ENABLED',
IsPremium: false,
IsOurDNS: true } ],
TotalItems: 1,
CurrentPage: 1,
PageSize: 20 }
domains
Methods to register and retrieve domains' info.
async create(
options: Create,
): RegistrationResult
Register a domain.
Create: Options to register a domain. https://www.namecheap.com/support/api/methods/domains/create.aspx
| Name | Type | Description | Default |
|---|---|---|---|
| domain* | string | The domain name to register. | - |
| years | number | The number of years to register. | 1 |
| promo | string | Promotional (coupon) code for the domain. Check https://www.namecheap.com/promos/coupons/ for this month's offers. | - |
| nameservers | string[] | The comma-separated list of custom nameservers to be associated with the domain name. | - |
| whois | boolean | Adds free WhoisGuard for the domain. | true |
| address* | AddressDetail | A single address to use for Registrant, Tech, Admin, and AuxBilling. Saved addresses can be found out with namecheap.users.address.getList and namecheap.users.address.getInfo. |
- |
| billingAddress | AddressDetail | An address to use for AuxBilling address details. |
- |
| registrantAddress | AddressDetail | An address to use for Registrant address details. |
- |
| techAddress | AddressDetail | An address to use for Tech address details. |
- |
| adminAddress | AddressDetail | An address to use for Admin address details. |
- |
RegistrationResult: Registered domain information.
| Name | Type | Description |
|---|---|---|
| ChargedAmount* | string | Total amount charged for registration. |
| Domain* | string | Domain name that you are trying to register. |
| DomainID* | number | Unique integer value that represents the domain. |
| NonRealTimeDomain* | boolean | Indicates whether the domain registration is instant (real-time) or not. |
| OrderID* | number | Unique integer value that represents the order. |
| Registered* | boolean | Indicates whether the domain was registered. |
| TransactionID* | number | Unique integer value that represents the transaction. |
| WhoisguardEnable* | boolean | Indicates whether WhoisGuard protection is enabled for the domain. |
/**
* @param {string} domain The domain to register.
* @param {NameCheap} client
*/
const Create = async (domain, client) => {
// Find the default address.
const ad = await client.users.address.getList()
const { AddressId } = ad.find(({ IsDefault }) => IsDefault)
const address = await client.users.address.getInfo(AddressId)
// Register a domain.
const res = await client.domains.create({
domain,
address,
})
return res
}{ Domain: 'rqt-example-2018-10-5-18-05-50.com',
Registered: true,
ChargedAmount: '9.0600',
DomainID: 330570,
OrderID: 1293341,
TransactionID: 1830869,
WhoisguardEnable: true,
FreePositiveSSL: false,
NonRealTimeDomain: false }async check(
options: string|Check,
): DomainCheck[]
Check a domain or domains for availability.
Check: Options to check a domain or domains. https://www.namecheap.com/support/api/methods/domains/check.aspx
| Name | Type | Description |
|---|---|---|
| domain | string | The domain check. |
| domains | string[] | The domains to check. |
DomainCheck: The result of the check.
| Name | Type | Description |
|---|---|---|
| Domain* | string | The domain name for which you wish to check availability. |
| Available* | boolean | Indicates whether the domain name is available for registration. |
| IsPremiumName* | boolean | Indicates whether the domain name is premium. |
| PremiumRegistrationPrice* | boolean | The registration price for the premium domain. |
| PremiumRenewalPrice* | boolean | The renewal price for the premium domain. |
| PremiumRestorePrice* | boolean | The restore price for the premium domain. |
| PremiumTransferPrice* | boolean | The transfer price for the premium domain. |
| EapFee* | number | Purchase fee for the premium domain during Early Access Program (EAP)*. |
| IcannFee* | number | Fee charged by ICANN. |
/**
* @param {string} domain The domain to check.
* @param {NameCheap} client
*/
const Check = async (domain, client) => {
// Check a domain with options.
const options = await client.domains.check({
domain,
})
// Simplified checking of a domain with a string.
const string = await client.domains.check(domain)
// Check multiple domains.
const array = await client.domains.check({
domains: [
domain,
domain.replace('.com', '.net'),
],
})
return {
options,
string,
array,
}
}{ options:
[ { Domain: 'example.com',
Available: false,
ErrorNo: 0,
Description: '',
IsPremiumName: false,
PremiumRegistrationPrice: 0,
PremiumRenewalPrice: 0,
PremiumRestorePrice: 0,
PremiumTransferPrice: 0,
IcannFee: 0,
EapFee: '0.0' } ],
string:
[ { Domain: 'example.com',
Available: false,
ErrorNo: 0,
Description: '',
IsPremiumName: false,
PremiumRegistrationPrice: 0,
PremiumRenewalPrice: 0,
PremiumRestorePrice: 0,
PremiumTransferPrice: 0,
IcannFee: 0,
EapFee: '0.0' } ],
array:
[ { Domain: 'example.com',
Available: false,
ErrorNo: 0,
Description: '',
IsPremiumName: false,
PremiumRegistrationPrice: 0,
PremiumRenewalPrice: 0,
PremiumRestorePrice: 0,
PremiumTransferPrice: 0,
IcannFee: 0,
EapFee: '0.0' },
{ Domain: 'example.net',
Available: false,
ErrorNo: 0,
Description: '',
IsPremiumName: false,
PremiumRegistrationPrice: 0,
PremiumRenewalPrice: 0,
PremiumRestorePrice: 0,
PremiumTransferPrice: 0,
IcannFee: 0,
EapFee: '0.0' } ] }async getInfo(
options: string|GetInfo,
): DomainInfo
Returns information about the requested domain.
GetInfo: Options to get info about a domain. https://www.namecheap.com/support/api/methods/domains/get-info.aspx
| Name | Type | Description |
|---|---|---|
| domain* | string | The domain to get info about. |
| host | string | The hosted domain name for which domain information needs to be requested. |
| Name | Type | Description |
|---|---|---|
| DomainName* | string | Domain name for which the information was requested, e.g., example.com. |
| OwnerName* | string | User account under which the domain is registered, e.g., rqt. |
| ID* | number | Unique integer value that represents the domain,e.g., 314928. |
| IsOwner* | boolean | Indicates whether the API user is the owner of the domain, e.g., true. |
| IsPremium* | boolean | Indicates whether the domain name is premium, e.g., false. |
| Status* | 'Ok'|'Locked'|'Expired' | Indicates the status of the domain, e.g., OK. |
| DomainDetails* | DomainDetails | |
| LockDetails* | LockDetails | |
| Whoisguard* | Whoisguard | |
| PremiumDnsSubscription* | PremiumDnsSubscription | |
| DnsDetails* | DnsDetails | |
| ModificationRights* | ModificationRights |
| Name | Type | Description |
|---|---|---|
| CreatedDate* | string | 06/06/2018 |
| ExpiredDate* | string | 06/06/2019 |
| NumYears* | number | 1 |
| Name | Type | Description |
|---|---|---|
| Enabled* | boolean | true |
| ID* | string | 264991 |
| ExpiredDate* | string | 06/06/2019 |
| EmailDetails* | EmailDetails |
| Name | Type | Description |
|---|---|---|
| AutoEmailChangeFrequencyDays* | number | 0 |
| ForwardedTo* | string | example@adc.sh |
| LastAutoEmailChangeDate* | string | |
| WhoisGuardEmail* | string | 43b596ee817f451f98eab1d848a4051a.protect@whoisguard.com |
| Name | Type | Description |
|---|---|---|
| CreatedDate* | Date | |
| ExpirationDate* | Date | |
| IsActive* | boolean | false |
| SubscriptionId* | number | -1 |
| UseAutoRenew* | boolean | false |
| Name | Type | Description |
|---|---|---|
| DynamicDNSStatus* | boolean | false |
| EmailType* | string | FWD |
| HostCount* | number | 2 |
| IsFailover* | boolean | false |
| IsUsingOurDNS* | boolean | true |
| Nameserver* | string[] | [dns1.registrar-servers.com, dns2.registrar-servers.com] |
| ProviderType* | 'CUSTOM'|'FREE' | FREE |
| Name | Type | Description |
|---|---|---|
| All* | boolean | true |
| hosts | boolean |
/**
* @param {string} domain The domain to get info about.
* @param {NameCheap} client
*/
const GetInfo = async (domain, client) => {
// Info with options.
await client.domains.getInfo({ domain })
// Simplified info with a string.
const res = await client.domains.getInfo(domain)
return res
}{ Status: 'Ok',
ID: 330571,
DomainName: 'rqt-example-2018-10-5-18-06-15.com',
OwnerName: 'zavr',
IsOwner: true,
IsPremium: false,
DomainDetails:
{ CreatedDate: '10/05/2018',
ExpiredDate: '10/05/2019',
NumYears: 0 },
Whoisguard:
{ Enabled: 'True',
ID: 269100,
ExpiredDate: '10/05/2019',
EmailDetails:
{ WhoisGuardEmail: '9663af3bce3040aab19742ce6f77b50f.protect@whoisguard.com',
ForwardedTo: 'zoidberg@futurama.bz',
LastAutoEmailChangeDate: '',
AutoEmailChangeFrequencyDays: 0 } },
PremiumDnsSubscription:
{ UseAutoRenew: false,
SubscriptionId: -1,
CreatedDate: 0000-12-31T21:00:00.000Z,
ExpirationDate: 0000-12-31T21:00:00.000Z,
IsActive: false },
DnsDetails:
{ ProviderType: 'FREE',
IsUsingOurDNS: true,
HostCount: 2,
EmailType: 'FWD',
DynamicDNSStatus: false,
IsFailover: false,
Nameserver: [ 'dns1.registrar-servers.com', 'dns2.registrar-servers.com' ] },
Modificationrights: { All: true } }async getList(
options?: GetList,
): { domains, TotalItems, CurrentPage, PageSize }
Returns a list of domains for the particular user.
GetList: Options to get a list of domains. https://www.namecheap.com/support/api/methods/domains/get-list.aspx
| Name | Type | Description | Default |
|---|---|---|---|
| type | 'ALL'|'EXPIRING'|'EXPIRED' | The type of domains. | ALL |
| filter | string | The keyword to look for in the domain list. | - |
| page | number | The page to return. | 1 |
| pageSize | number | The number of domains to be listed on a page. Minimum value is 10, and maximum value is 100. | 20 |
| sort | 'name'|'expire'|'create' | The field by which to sort domains. If not given, the domains are sorted in descending order by their creation date. | create |
| desc | boolean | Whether to sort in descending order. | false |
| Name | Type | Description |
|---|---|---|
| AutoRenew* | boolean | false |
| Created* | string | 07/23/2018 |
| Expires* | string | 07/23/2019 |
| ID* | number | 314928 |
| IsExpired* | boolean | false |
| IsLocked* | boolean | false |
| IsOurDNS* | boolean | true |
| IsPremium* | boolean | false |
| Name* | string | domain.app |
| User* | string | user |
| WhoisGuard* | string | ENABLED |
/**
* @param {string} domain The domain to filter by.
* @param {NameCheap} client
*/
const GetList = async (domain, client) => {
const res = await client.domains.getList({
filter: domain,
})
return res
}{ domains:
[ { ID: 330572,
Name: 'rqt-example-2018-10-5-18-06-28.com',
User: 'zavr',
Created: '10/05/2018',
Expires: '10/05/2019',
IsExpired: false,
IsLocked: false,
AutoRenew: false,
WhoisGuard: 'ENABLED',
IsPremium: false,
IsOurDNS: true } ],
TotalItems: 1,
CurrentPage: 1,
PageSize: 20 }users.address
Methods to manipulate addresses.
async getInfo(
id: string|number,
): AddressDetail
Gets information for the requested address ID.
| Name | Type | Description |
|---|---|---|
| EmailAddress* | string | Email address of the user. |
| FirstName* | string | First name of the user. |
| LastName* | string | Last name of the user. |
| JobTitle | string | Job designation of the user |
| Organization | string | Organization of the user. |
| Address1* | string | StreetAddress1 of the user. |
| Address2 | string | StreetAddress2 of the user. |
| City* | string | City of the user. |
| StateProvince* | string | State/Province of the user. |
| StateProvinceChoice* | 'S'|'P' | State/Province choice of the user. |
| Zip* | string | Zip/Postal code of the user. |
| Country* | string | Two letter country code of the user. |
| Phone* | string | Phone number in the format +NNN.NNNNNNNNNN. |
| PhoneExt | string | PhoneExt of the user. |
| Fax | string | Fax number in the format +NNN.NNNNNNNNNN. |
/**
* @param {string|number} id The address to get info about.
* @param {NameCheap} client
*/
const GetInfo = async (id, client) => {
const res = await client.users.address.getInfo(id)
return res
}{ AddressId: 101235,
UserName: 'zavr',
AddressName: 'Planet Express',
Default_YN: true,
FirstName: 'John',
LastName: 'Zoidberg',
JobTitle: 'Doctor',
Organization: 'Planet Express',
Address1: 'Planet Express',
Address2: '57th Street',
City: 'New New York',
StateProvince: 'NY',
StateProvinceChoice: 'S',
Zip: '10019',
Country: 'US',
Phone: '+1.5417543010',
PhoneExt: '',
EmailAddress: 'zoidberg@futurama.bz' }async getList(): Address[]
Gets a list of address IDs and address names associated with the user account.
| Name | Type | Description |
|---|---|---|
| AddressId* | number | A unique integer value that represents the address profile. |
| AddressName* | number | The name of the address profile. |
| IsDefault* | boolean | Whether it is a default address. |
/**
* @param {NameCheap} client
*/
const GetList = async (client) => {
const res = await client.users.address.getList()
return res
}[ { AddressId: 0,
AddressName: 'Primary Address',
IsDefault: false },
{ AddressId: 101235,
AddressName: 'Planet Express',
IsDefault: true } ]Progress
domains: 4/11domains.dns: 0/7domains.ns: 0/4domains.transfer: 0/4ssl: 0/13users: 0/9users.address: 2/6whoisguard: 0/8
6/62 = 10%
Copyright
(c) Rqt 2018
