# Renew a domain

Extend the registration period of a domain in your reseller account.

Extend the registration of a domain you already hold. This creates a renewal order and charges your reseller credits.

`POST /order/domains/renew`

Send the body as `application/x-www-form-urlencoded`. Authenticate with the `username` and `token` headers described in [Authentication](/guides/authentication).

## Parameters

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

<ParamField body="regperiod" type="numeric" required>
  Number of years to add to the current registration. Must be a period the TLD offers (see [TLDs](/api-reference/tlds)).
</ParamField>

<ParamField body="addons" type="object">
  Optional add-ons to renew alongside the domain, sent as `addons[dnsmanagement]`, `addons[emailforwarding]`, and `addons[idprotection]`, each `1` or `0`. See the [Addons model](/api-reference/models).
</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/order/domains/renew" \
  -H "username: $EMAIL" \
  -H "token: $TOKEN" \
  --data "domain=hostraha-demo-42.com" \
  --data "regperiod=1" \
  --data "addons[dnsmanagement]=1" \
  --data "addons[idprotection]=1"
```

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

$fields = [
    "domain"    => "hostraha-demo-42.com",
    "regperiod" => 1,
    "addons"    => [
        "dnsmanagement" => 1,
        "idprotection"  => 1,
    ],
];

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "{$endpoint}/order/domains/renew");
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()

resp = requests.post(
    f"{ENDPOINT}/order/domains/renew",
    headers={"username": EMAIL, "token": token()},
    data={
        "domain": "hostraha-demo-42.com",
        "regperiod": 1,
        "addons[dnsmanagement]": 1,
        "addons[idprotection]": 1,
    },
)
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 body = new URLSearchParams();
body.append("domain", "hostraha-demo-42.com");
body.append("regperiod", "1");
body.append("addons[dnsmanagement]", "1");
body.append("addons[idprotection]", "1");

const res = await fetch(`${ENDPOINT}/order/domains/renew`, {
  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() {
	form := url.Values{}
	form.Set("domain", "hostraha-demo-42.com")
	form.Set("regperiod", "1")
	form.Set("addons[dnsmanagement]", "1")
	form.Set("addons[idprotection]", "1")

	req, _ := http.NewRequest("POST", endpoint+"/order/domains/renew", 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"
```

The renewal charges your reseller credits for the added period. See [Credits and billing](/guides/credits-and-billing).
