# Register a domain

Order a new domain registration with nameservers, contacts, and optional add-ons.

Order a new domain registration. This creates an order, deducts your reseller credits, and provisions the domain to your account once the account and order are active.

`POST /order/domains/register`

Send the body as `application/x-www-form-urlencoded`. Nested values use PHP bracket notation, for example `nameservers[ns1]=...` and `contacts[registrant][firstname]=...`. Authenticate with the `username` and `token` headers described in [Authentication](/guides/authentication).

## Parameters

<ParamField body="domain" type="text" required>
  The full domain to register, for example `hostraha-demo-42.com`.
</ParamField>

<ParamField body="regperiod" type="numeric" required>
  Registration period in years. Must be a period the TLD offers (see [TLDs](/api-reference/tlds)).
</ParamField>

<ParamField body="nameservers" type="object" required>
  The domain's nameservers, sent as `nameservers[ns1]`…`nameservers[ns5]`. `ns1` and `ns2` are required; `ns3`–`ns5` are optional. See the [Nameservers model](/api-reference/models).
</ParamField>

<ParamField body="contacts" type="object" required>
  The registrant, tech, billing, and admin contacts, sent as `contacts[registrant][...]`, `contacts[tech][...]`, `contacts[billing][...]`, and `contacts[admin][...]`. See the [Contacts model](/api-reference/models) for the fields in each contact.
</ParamField>

<ParamField body="domainfields" type="text">
  TLD-specific registration fields, required by some TLDs (for example a registrant ID). Sent as nested `domainfields[...]` values.
</ParamField>

<ParamField body="addons" type="object">
  Optional add-ons, sent as `addons[dnsmanagement]`, `addons[emailforwarding]`, and `addons[idprotection]`, each `1` to enable or `0` to disable. See the [Addons model](/api-reference/models).
</ParamField>

## Request

The examples send a complete order: two nameservers, a full registrant contact reused for tech, billing, and admin, and all three add-ons enabled. Replace the placeholder credentials and contact details with your own.

<CodeGroup>
```bash cURL
API_KEY="your-api-key"
EMAIL="you@example.com"
ENDPOINT="https://portal.hostraha.com/modules/addons/DomainsReseller/api/index.php"
TS=$(date -u +"%y-%m-%d %H")
TOKEN=$(printf '%s' "$API_KEY" \
  | openssl dgst -sha256 -hmac "$EMAIL:$TS" -hex \
  | sed 's/^.*= //' | tr -d '\n' | base64 -w0)

curl -s "$ENDPOINT/order/domains/register" \
  -H "username: $EMAIL" \
  -H "token: $TOKEN" \
  --data "domain=hostraha-demo-42.com" \
  --data "regperiod=1" \
  --data "nameservers[ns1]=ns1.hostraha.com" \
  --data "nameservers[ns2]=ns2.hostraha.com" \
  --data "addons[dnsmanagement]=1" \
  --data "addons[emailforwarding]=1" \
  --data "addons[idprotection]=1" \
  --data "contacts[registrant][firstname]=Jane" \
  --data "contacts[registrant][lastname]=Doe" \
  --data "contacts[registrant][fullname]=Jane Doe" \
  --data "contacts[registrant][companyname]=Hostraha" \
  --data "contacts[registrant][email]=you@example.com" \
  --data "contacts[registrant][address1]=123 Example Street" \
  --data "contacts[registrant][city]=Nairobi" \
  --data "contacts[registrant][state]=Nairobi" \
  --data "contacts[registrant][postcode]=00100" \
  --data "contacts[registrant][country]=KE" \
  --data "contacts[registrant][phonenumber]=+15555550100" \
  --data "contacts[tech][firstname]=Jane" \
  --data "contacts[tech][lastname]=Doe" \
  --data "contacts[tech][fullname]=Jane Doe" \
  --data "contacts[tech][companyname]=Hostraha" \
  --data "contacts[tech][email]=you@example.com" \
  --data "contacts[tech][address1]=123 Example Street" \
  --data "contacts[tech][city]=Nairobi" \
  --data "contacts[tech][state]=Nairobi" \
  --data "contacts[tech][postcode]=00100" \
  --data "contacts[tech][country]=KE" \
  --data "contacts[tech][phonenumber]=+15555550100" \
  --data "contacts[billing][firstname]=Jane" \
  --data "contacts[billing][lastname]=Doe" \
  --data "contacts[billing][fullname]=Jane Doe" \
  --data "contacts[billing][companyname]=Hostraha" \
  --data "contacts[billing][email]=you@example.com" \
  --data "contacts[billing][address1]=123 Example Street" \
  --data "contacts[billing][city]=Nairobi" \
  --data "contacts[billing][state]=Nairobi" \
  --data "contacts[billing][postcode]=00100" \
  --data "contacts[billing][country]=KE" \
  --data "contacts[billing][phonenumber]=+15555550100" \
  --data "contacts[admin][firstname]=Jane" \
  --data "contacts[admin][lastname]=Doe" \
  --data "contacts[admin][fullname]=Jane Doe" \
  --data "contacts[admin][companyname]=Hostraha" \
  --data "contacts[admin][email]=you@example.com" \
  --data "contacts[admin][address1]=123 Example Street" \
  --data "contacts[admin][city]=Nairobi" \
  --data "contacts[admin][state]=Nairobi" \
  --data "contacts[admin][postcode]=00100" \
  --data "contacts[admin][country]=KE" \
  --data "contacts[admin][phonenumber]=+15555550100"
```

```php PHP
<?php
$apiKey   = "your-api-key";
$email    = "you@example.com";
$endpoint = "https://portal.hostraha.com/modules/addons/DomainsReseller/api/index.php";

$token = base64_encode(hash_hmac("sha256", $apiKey, "{$email}:" . gmdate("y-m-d H")));

$contact = [
    "firstname"   => "Jane",
    "lastname"    => "Doe",
    "fullname"    => "Jane Doe",
    "companyname" => "Hostraha",
    "email"       => "you@example.com",
    "address1"    => "123 Example Street",
    "city"        => "Nairobi",
    "state"       => "Nairobi",
    "postcode"    => "00100",
    "country"     => "KE",
    "phonenumber" => "+15555550100",
];

$fields = [
    "domain"      => "hostraha-demo-42.com",
    "regperiod"   => 1,
    "nameservers" => [
        "ns1" => "ns1.hostraha.com",
        "ns2" => "ns2.hostraha.com",
    ],
    "addons" => [
        "dnsmanagement"   => 1,
        "emailforwarding" => 1,
        "idprotection"    => 1,
    ],
    "contacts" => [
        "registrant" => $contact,
        "tech"       => $contact,
        "billing"    => $contact,
        "admin"      => $contact,
    ],
];

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "{$endpoint}/order/domains/register");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($curl, CURLOPT_HTTPHEADER, [
    "username: {$email}",
    "token: {$token}",
]);
$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

```python Python
from datetime import datetime, timezone

API_KEY  = "your-api-key"
EMAIL    = "you@example.com"
ENDPOINT = "https://portal.hostraha.com/modules/addons/DomainsReseller/api/index.php"

def token() -> str:
    ts = datetime.now(timezone.utc).strftime("%y-%m-%d %H")
    digest = hmac.new(f"{EMAIL}:{ts}".encode(), API_KEY.encode(), hashlib.sha256).hexdigest()
    return base64.b64encode(digest.encode()).decode()

contact = {
    "firstname": "Jane",
    "lastname": "Doe",
    "fullname": "Jane Doe",
    "companyname": "Hostraha",
    "email": "you@example.com",
    "address1": "123 Example Street",
    "city": "Nairobi",
    "state": "Nairobi",
    "postcode": "00100",
    "country": "KE",
    "phonenumber": "+15555550100",
}

data = {
    "domain": "hostraha-demo-42.com",
    "regperiod": 1,
    "nameservers[ns1]": "ns1.hostraha.com",
    "nameservers[ns2]": "ns2.hostraha.com",
    "addons[dnsmanagement]": 1,
    "addons[emailforwarding]": 1,
    "addons[idprotection]": 1,
}
for role in ("registrant", "tech", "billing", "admin"):
    for key, value in contact.items():
        data[f"contacts[{role}][{key}]"] = value

resp = requests.post(
    f"{ENDPOINT}/order/domains/register",
    headers={"username": EMAIL, "token": token()},
    data=data,
)
print(resp.json())
```

```javascript Node.js

const API_KEY  = "your-api-key";
const EMAIL    = "you@example.com";
const ENDPOINT = "https://portal.hostraha.com/modules/addons/DomainsReseller/api/index.php";

function token() {
  const ts = new Date().toISOString().slice(2, 13).replace("T", " "); // "yy-mm-dd HH" UTC
  const digest = crypto.createHmac("sha256", `${EMAIL}:${ts}`).update(API_KEY).digest("hex");
  return Buffer.from(digest, "utf8").toString("base64");
}

const contact = {
  firstname: "Jane",
  lastname: "Doe",
  fullname: "Jane Doe",
  companyname: "Hostraha",
  email: "you@example.com",
  address1: "123 Example Street",
  city: "Nairobi",
  state: "Nairobi",
  postcode: "00100",
  country: "KE",
  phonenumber: "+15555550100",
};

const body = new URLSearchParams();
body.append("domain", "hostraha-demo-42.com");
body.append("regperiod", "1");
body.append("nameservers[ns1]", "ns1.hostraha.com");
body.append("nameservers[ns2]", "ns2.hostraha.com");
body.append("addons[dnsmanagement]", "1");
body.append("addons[emailforwarding]", "1");
body.append("addons[idprotection]", "1");
for (const role of ["registrant", "tech", "billing", "admin"]) {
  for (const [key, value] of Object.entries(contact)) {
    body.append(`contacts[${role}][${key}]`, value);
  }
}

const res = await fetch(`${ENDPOINT}/order/domains/register`, {
  method: "POST",
  headers: { username: EMAIL, token: token() },
  body,
});
console.log(await res.json());
```

```go Go
package main

	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
	"fmt"
	"io"
	"net/http"
	"net/url"
	"strings"
	"time"
)

const (
	apiKey   = "your-api-key"
	email    = "you@example.com"
	endpoint = "https://portal.hostraha.com/modules/addons/DomainsReseller/api/index.php"
)

func token() string {
	ts := time.Now().UTC().Format("06-01-02 15") // yy-mm-dd HH
	mac := hmac.New(sha256.New, []byte(email+":"+ts))
	mac.Write([]byte(apiKey))
	return base64.StdEncoding.EncodeToString([]byte(hex.EncodeToString(mac.Sum(nil))))
}

func main() {
	contact := map[string]string{
		"firstname":   "Jane",
		"lastname":    "Doe",
		"fullname":    "Jane Doe",
		"companyname": "Hostraha",
		"email":       "you@example.com",
		"address1":    "123 Example Street",
		"city":        "Nairobi",
		"state":       "Nairobi",
		"postcode":    "00100",
		"country":     "KE",
		"phonenumber": "+15555550100",
	}

	form := url.Values{}
	form.Set("domain", "hostraha-demo-42.com")
	form.Set("regperiod", "1")
	form.Set("nameservers[ns1]", "ns1.hostraha.com")
	form.Set("nameservers[ns2]", "ns2.hostraha.com")
	form.Set("addons[dnsmanagement]", "1")
	form.Set("addons[emailforwarding]", "1")
	form.Set("addons[idprotection]", "1")
	for _, role := range []string{"registrant", "tech", "billing", "admin"} {
		for key, value := range contact {
			form.Set(fmt.Sprintf("contacts[%s][%s]", role, key), value)
		}
	}

	req, _ := http.NewRequest("POST", endpoint+"/order/domains/register", strings.NewReader(form.Encode()))
	req.Header.Set("username", email)
	req.Header.Set("token", token())
	req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}
```
</CodeGroup>

## Response

On success the endpoint returns the bare JSON string `"success"`.

```json
"success"
```

A `"success"` response charges your reseller credits and creates the order. The domain provisions to your account once the account and order are active. Until then, the management endpoints return a `403` "not found in reseller account". See [Credits and billing](/guides/credits-and-billing) for how ordering draws down your balance.
