Skip to content

An API to namecheap.com via the web interface, with an ability to log in using 2-factor Auth and check Whois.

License

Notifications You must be signed in to change notification settings

rqt/namecheap-web

Repository files navigation

namecheap

@rqt/namecheap-web

npm version

@rqt/namecheap-web is an API to namecheap.com via the web interface, with an ability to log in using 2-factor Auth, check Whois and retrieve a coupon code.

The web API is currently used in the Expensive package to authenticate and white-list IP addresses. This is useful for dynamic-IP holders. Because the API implemented with gzip compression, the amount of traffic is minimized as well, helping to save data on mobile networks.

yarn add @rqt/namecheap-web

Table Of Contents

API

The package is available by importing its default class:

import NamecheapWeb from '@rqt/namecheap-web'

constructor(
  options=: WebOptions,
): NamecheapWeb

Create a new instance of the NamecheapWeb class. The sandbox version can be specified in the options.

  • options WebOptions (optional): Options for the web client.

To remember the session cookies on the local filesystem, the readSession parameter can be passed. On the production version, the session expires after 20 minutes, but can be renewed after 10 minutes of using an existing session.

WebOptions: Options for the web client.

Name Type & Description Default
sandbox boolean false
Whether to use the sandbox version.
readSession boolean false
Read and store the cookies for the session from the local file.
sessionFile string .namecheap-web.json
If reading session, indicates the file where to store cookies.
/* yarn example/ */
import NamecheapWeb from '@rqt/namecheap-web'
import bosom from 'bosom'

(async () => {
  try {
    // 0. Read stored username and password from a local file.
    const { username, password } = await bosom('.auth-sandbox.json')
    const nw = new NamecheapWeb({
      sandbox: true,
      readSession: true, // save cookies in a file.
    })
    // 1. Authenticate and create a session.
    await nw.auth(username, password)

    // 2. Read white-listed IPs.
    const ips = await nw.getWhitelistedIPList()
    console.log(JSON.stringify(ips[0], null, 2))

    // 3. Whitelist a new IP.
    const ip = await NamecheapWeb.LOOKUP_IP()
    await nw.whitelistIP(ip, 'example')

    // 4. Remove white-listed IP.
    await nw.removeWhitelistedIP('example')
  } catch ({ message }) {
    console.error(message)
  }
})()

async auth(
  username: string,
  password: string,
  phone=: string,
  force=: boolean,
): !Promise

Authenticate the app and obtain the cookies.

  • username* string: The username to log in with.
  • password* string: The password to enter.
  • phone string (optional): The phone number to select for 2-factor auth.
  • force boolean (optional): Try to log in even if session exists.

If 2-factor authentication is enabled, it will also be carried out. The phone argument can be passed which is the last 3 digits of the phone used to receive the confirmation text. If it is not passed, a question will be asked via the CLI. The code should be then entered in the CLI as well.

async static LOOKUP_IP(): string

Get the public IP address using https://api.ipify.org.

async static WHOIS(domain): string

Return WHOIS data for the domain.

import NamecheapWeb from '@rqt/namecheap-web'

(async () => {
  try {
    const res = await NamecheapWeb.WHOIS('test.org')
    console.log(res)
  } catch ({ message }) {
    console.error(message)
  }
})()
Show whois data
Domain Name: test.org
Registry Domain ID: D380528-LROR
Registrar WHOIS Server: whois.psi-usa.info
Registrar URL: https://www.psi-usa.info
Updated Date: 2019-09-14T07:09:46Z
Creation Date: 1997-07-27T04:00:00Z
Registrar Registration Expiration Date: 2020-10-15T16:17:16Z
Registrar: PSI-USA, Inc. dba Domain Robot
Registrar IANA ID: 151
Registrar Abuse Contact Email: domain-abuse@psi-usa.info
Registrar Abuse Contact Phone: +49.94159559482
Domain Status: clientTransferProhibited https://www.icann.org/epp#clientTransferProhibited
Registry Registrant ID: REDACTED FOR PRIVACY
Registrant Name: REDACTED FOR PRIVACY
Registrant Organization: TMT Teleservice GmbH & Co.KG
Registrant Street: REDACTED FOR PRIVACY
Registrant City: REDACTED FOR PRIVACY
Registrant State/Province: Bayern
Registrant Postal Code: REDACTED FOR PRIVACY
Registrant Country: DE
Registrant Phone: REDACTED FOR PRIVACY
Registrant Phone Ext: REDACTED FOR PRIVACY
Registrant Fax: REDACTED FOR PRIVACY
Registrant Fax Ext: REDACTED FOR PRIVACY
Registrant Email: https://contact.domain-robot.org/test.org
Registry Admin ID: REDACTED FOR PRIVACY
Admin Name: REDACTED FOR PRIVACY
Admin Organization: REDACTED FOR PRIVACY
Admin Street: REDACTED FOR PRIVACY
Admin City: REDACTED FOR PRIVACY
Admin State/Province: REDACTED FOR PRIVACY
Admin Postal Code: REDACTED FOR PRIVACY
Admin Country: REDACTED FOR PRIVACY
Admin Phone: REDACTED FOR PRIVACY
Admin Phone Ext: REDACTED FOR PRIVACY
Admin Fax: REDACTED FOR PRIVACY
Admin Fax Ext: REDACTED FOR PRIVACY
Admin Email: https://contact.domain-robot.org/test.org
Registry Tech ID: REDACTED FOR PRIVACY
Tech Name: REDACTED FOR PRIVACY
Tech Organization: REDACTED FOR PRIVACY
Tech Street: REDACTED FOR PRIVACY
Tech City: REDACTED FOR PRIVACY
Tech State/Province: REDACTED FOR PRIVACY
Tech Postal Code: REDACTED FOR PRIVACY
Tech Country: REDACTED FOR PRIVACY
Tech Phone: REDACTED FOR PRIVACY
Tech Phone Ext: REDACTED FOR PRIVACY
Tech Fax: REDACTED FOR PRIVACY
Tech Fax Ext: REDACTED FOR PRIVACY
Tech Email: https://contact.domain-robot.org/test.org
Name Server: ns0.tmt.de
Name Server: ns2.tmt.de
Name Server: ns3.tmt.de
Name Server: ns4.tmt.de
Name Server: ns1.tmt.de
DNSSEC: unsigned
URL of the ICANN WHOIS Data Problem Reporting System: https://wdprs.internic.net/
>>> Last update of WHOIS database: 2020-01-07T22:34:28Z <<<

For more information on Whois status codes, please visit https://www.icann.org/epp


# Terms and conditions:
#
# The data in the WHOIS database of PSI-USA, Inc. is provided by
# PSI-USA, Inc. for information purposes, and to assist persons in
# obtaining information about or related to a domain name registration
# record.  PSI-USA, Inc. does not guarantee its accuracy.  By submitting
# a WHOIS query, you agree that you will use this data only for lawful
# purposes and that, under no circumstances, you will use this data to
#  (1) allow, enable, or otherwise support the transmission of mass
#      unsolicited, commercial advertising or solicitations via E-mail
#      (spam); or
#  (2) enable high volume, automated, electronic processes that apply to
#      PSI-USA, Inc. or its systems.
# PSI-USA, Inc. reserves the right to modify these terms at any time.
# By submitting this query, you agree to abide by this policy.
#

async static COUPON(): string

Returns this month's coupon from the https://www.namecheap.com/promos/coupons/ page.

/* yarn example/whois.js */
import NamecheapWeb from '@rqt/namecheap-web'

(async () => {
  try {
    const res = await NamecheapWeb.COUPON()
    console.log(res)
  } catch ({ message }) {
    console.error(message)
  }
})()
TLDEALZ01

async static SANDBOX_COUPON(): string

Returns this month's coupon from the https://www.sandbox.namecheap.com/promos/coupons/ page.

import NamecheapWeb from '@rqt/namecheap-web'

(async () => {
  try {
    const res = await NamecheapWeb.SANDBOX_COUPON()
    console.log(res)
  } catch ({ message }) {
    console.error(message)
  }
})()
TLDEALZ01

async getWhitelistedIPList(): !Promise<!Array<!_namecheap.WhitelistedIP>>

Get a list of white-listed IP addresses which can make API calls. The maximum of 20 IP addresses is allowed.

WhitelistedIP: A white-listed IP which can be used for API calls.

Name Type & Description
Name* string
The name of the IP.
IpAddress* string
The IP address.
ModifyDate* !Date
The modification date.

async whitelistIP(
  ip: string,
  name=: string,
): !Promise

Add an IP address to the white-listed IPs.

  • ip* string: The IP to add.
  • name string (optional): The name to save the IP as. If not given, it is automatically generated as rqt {date}.

async removeWhitelistedIP(
  name: string,
): !Promise

Remove the IP from the white-listed IPs by its name.

  • name* string: The name of the saved IP to remove.

Copyright

Art Deco © Art Deco for Rqt 2020 Tech Nation Visa Tech Nation Visa Sucks

About

An API to namecheap.com via the web interface, with an ability to log in using 2-factor Auth and check Whois.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published