# Registrar lock

Read and set the registrar (transfer) lock on a domain.

Read and set the registrar lock on a domain. A locked domain rejects unauthorized transfer requests at the registry.

## Get registrar lock

Return the current lock state of a domain.

`GET /domains/{domain}/lock`

### 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/lock" \
  -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/lock");
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/lock",
                    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/lock`, {
  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/lock", 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

```json
"unlocked"
```

The value is `"locked"` or `"unlocked"`.

## Save registrar lock

Set the lock state of a domain.

`POST /domains/{domain}/lock`

### Parameters

<ParamField path="domain" type="text" required>
  The domain to update, for example `example.com`.
</ParamField>
<ParamField body="lockstatus" type="text" required>
  The lock state to apply: `locked` or `unlocked`.
</ParamField>

### Request

<CodeGroup>
```bash cURL
curl -s "$ENDPOINT/domains/example.com/lock" \
  -H "username: $EMAIL" \
  -H "token: $TOKEN" \
  --data "lockstatus=locked"
```

```php PHP
<?php
// Reuse the auth setup from the get example above.
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "{$endpoint}/domains/example.com/lock");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query(["lockstatus" => "locked"]));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
    "username: {$email}",
    "token: {$token}",
]);
echo curl_exec($curl);
curl_close($curl);
```

```python Python
resp = requests.post(f"{ENDPOINT}/domains/example.com/lock",
                     headers={"username": EMAIL, "token": token()},
                     data={"lockstatus": "locked"})
print(resp.json())
```

```javascript Node.js
const body = new URLSearchParams({ lockstatus: "locked" });

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

```go Go
form := url.Values{}
form.Set("lockstatus", "locked")

req, _ := http.NewRequest("POST", endpoint+"/domains/example.com/lock", 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>

<Note>
  The Go save snippet reuses the `token()` helper from the get example and also needs the `net/url` and `strings` imports.
</Note>

### Response

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

<ResponseField name="status" type="string">
  `success` when the lock state is applied.
</ResponseField>
<ResponseField name="success" type="string">
  Mirrors `status`.
</ResponseField>
<ResponseField name="message" type="string">
  Empty on success, or an error description on failure.
</ResponseField>
