api.domains

add()

api.domains.add(name) → Promise<Domain>

Attaches a domain and hands back the nameservers to set at the registrar. The zone starts empty, and nothing is written.

writes nothingone account per namenameservers come back
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

const domain = await api.domains.add("example.com");

domain.status;        // "pending_nameservers"
domain.nameservers;   // the pair to set at the registrar
domain = api.domains.add("example.com")

domain.status        # "pending_nameservers"
domain.nameservers   # the pair to set at the registrar

The zone starts empty — and that is the trap

Do not tell the customer to switch yet

A domain bought elsewhere already serves a site and mailboxes. Pointing the registrar at an empty zone stops all of it at that second. Read migration() first, and import() if it says so.

A search of what the domain serves today runs on attach, and what it finds feeds migration() and import(). Nothing is posed in the zone.

The whole sequence

const domain = await api.domains.add("example.com");

const plan = await domain.migration();
if (!plan.safeToSwitch) {
  const { added, skipped } = await domain.records.import();
  console.log(added, "copied,", skipped.length, "to do by hand");
}

// Now the registrar can be pointed at domain.nameservers
await domain.check();
domain = api.domains.add("example.com")

plan = domain.migration()
if not plan["safeToSwitch"]:
    result = domain.records.import_zone()
    print(result.get("added"), "copied,", len(result.get("skipped") or []), "to do by hand")

# Now the registrar can be pointed at domain.nameservers
domain.check()

A name belongs to one account

domain_taken on a second attempt: the second account would overwrite the first one's zone.

Read the nameservers, do not hardcode them

They are stored per domain and come back on the object. Writing a pair into your own code is the kind of thing that works until the day it does not.