# Contact details

Read and update the registrant, admin, technical, and billing contacts on a domain.

Read and update the WHOIS contacts on a domain: the registrant, admin, technical, and billing parties.

## Get contact details

Return the current contact set for a domain.

`GET /domains/{domain}/contact`

### Parameters

<ParamField path="domain" type="text" required>
  The domain to read, for example `example.com`.
</ParamField>

### Request

<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/domains/example.com/contact" \
  -H "username: $EMAIL" \
  -H "token: $TOKEN"
```

```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")));

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "{$endpoint}/domains/example.com/contact");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
    "username: {$email}",
    "token: {$token}",
]);
echo curl_exec($curl);
curl_close($curl);
```

```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()

resp = requests.get(f"{ENDPOINT}/domains/example.com/contact",
                    headers={"username": EMAIL, "token": token()})
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 res = await fetch(`${ENDPOINT}/domains/example.com/contact`, {
  headers: { username: EMAIL, token: token() },
});
console.log(await res.json());
```

```go Go
package main

	"crypto/hmac"
	"crypto/sha256"
	"encoding/base64"
	"encoding/hex"
	"fmt"
	"io"
	"net/http"
	"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() {
	req, _ := http.NewRequest("GET", endpoint+"/domains/example.com/contact", nil)
	req.Header.Set("username", email)
	req.Header.Set("token", token())
	resp, _ := http.DefaultClient.Do(req)
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}
```
</CodeGroup>

### Response

Once the domain is active, this returns the stored contact set. Before the domain is provisioned to your account, it returns an empty array:

```json
[]
```

## Save contact details

Replace the contact set on a domain.

`POST /domains/{domain}/contact`

### Parameters

<ParamField path="domain" type="text" required>
  The domain to update, for example `example.com`.
</ParamField>

<ParamField body="contactdetails" type="object" required>
  The full contact set, keyed by role: `Registrant`, `Technical`, `Billing`, and `Admin`. Each value is a [Contact](/api-reference/models) object.
</ParamField>

<Note>
  The save keys are capitalized (`Registrant`, `Technical`, `Billing`, `Admin`) and differ from the lowercase `contacts` keys used when ordering (`registrant`, `tech`, `billing`, `admin`). See [Models](/api-reference/models).
</Note>

Encode each contact with nested bracket notation, for example `contactdetails[Registrant][firstname]=Jane`.

### Request

<CodeGroup>
```bash cURL
curl -s "$ENDPOINT/domains/example.com/contact" \
  -H "username: $EMAIL" \
  -H "token: $TOKEN" \
  --data "contactdetails[Registrant][firstname]=Jane" \
  --data "contactdetails[Registrant][lastname]=Doe" \
  --data "contactdetails[Registrant][fullname]=Jane Doe" \
  --data "contactdetails[Registrant][companyname]=Hostraha" \
  --data "contactdetails[Registrant][email]=you@example.com" \
  --data "contactdetails[Registrant][address1]=123 Example Street" \
  --data "contactdetails[Registrant][city]=Nairobi" \
  --data "contactdetails[Registrant][state]=Nairobi" \
  --data "contactdetails[Registrant][postcode]=00100" \
  --data "contactdetails[Registrant][country]=KE" \
  --data "contactdetails[Registrant][phonenumber]=+1.5555550100" \
  --data "contactdetails[Technical][firstname]=Jane" \
  --data "contactdetails[Technical][lastname]=Doe" \
  --data "contactdetails[Technical][email]=you@example.com" \
  --data "contactdetails[Billing][firstname]=Jane" \
  --data "contactdetails[Billing][lastname]=Doe" \
  --data "contactdetails[Billing][email]=you@example.com" \
  --data "contactdetails[Admin][firstname]=Jane" \
  --data "contactdetails[Admin][lastname]=Doe" \
  --data "contactdetails[Admin][email]=you@example.com"
```

```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" => "+1.5555550100",
];

$fields = http_build_query([
    "contactdetails" => [
        "Registrant" => $contact,
        "Technical"  => $contact,
        "Billing"    => $contact,
        "Admin"      => $contact,
    ],
]);

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

```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": "+1.5555550100",
}
data = {
    f"contactdetails[{role}][{key}]": value
    for role in ("Registrant", "Technical", "Billing", "Admin")
    for key, value in contact.items()
}

resp = requests.post(f"{ENDPOINT}/domains/example.com/contact",
                     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: "+1.5555550100",
};

const body = new URLSearchParams();
for (const role of ["Registrant", "Technical", "Billing", "Admin"]) {
  for (const [key, value] of Object.entries(contact)) {
    body.append(`contactdetails[${role}][${key}]`, value);
  }
}

const res = await fetch(`${ENDPOINT}/domains/example.com/contact`, {
  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": "+1.5555550100",
	}
	form := url.Values{}
	for _, role := range []string{"Registrant", "Technical", "Billing", "Admin"} {
		for key, value := range contact {
			form.Set(fmt.Sprintf("contactdetails[%s][%s]", role, key), value)
		}
	}

	req, _ := http.NewRequest("POST", endpoint+"/domains/example.com/contact", 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, _ := http.DefaultClient.Do(req)
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)
	fmt.Println(string(body))
}
```
</CodeGroup>

### Response

```json
{"status":"success","message":"","success":"success"}
```

<ResponseField name="status" type="string">
  `success` when the contacts are saved.
</ResponseField>
<ResponseField name="success" type="string">
  Mirrors `status`; `success` on a successful save.
</ResponseField>
<ResponseField name="message" type="string">
  Empty on success, or an error description on failure.
</ResponseField>
