# Account

Read your reseller credit balance and the API version.

Use these endpoints to check your available reseller credits and confirm which API version you are calling. Both take no parameters and authenticate with the `username` and `token` headers described in [Authentication](/guides/authentication).

## Get credits

Return your available reseller credit balance.

`GET /billing/credits`

The balance is returned as a bare JSON string in your account currency. Ordering, renewing, and transferring domains draw down this balance — see [Credits and billing](/guides/credits-and-billing).

## Get version

Return the API version. This is also the simplest call to confirm your credentials and token are valid.

`GET /version`

## Request

The examples below call both endpoints in sequence, reusing one computed token.

<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/billing/credits" -H "username: $EMAIL" -H "token: $TOKEN"
curl -s "$ENDPOINT/version"         -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")));

function call(string $url, string $email, string $token): string {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, [
        "username: {$email}",
        "token: {$token}",
    ]);
    $response = curl_exec($curl);
    curl_close($curl);
    return $response;
}

echo call("{$endpoint}/billing/credits", $email, $token) . "\n";
echo call("{$endpoint}/version", $email, $token) . "\n";
```

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

headers = {"username": EMAIL, "token": token()}
print(requests.get(f"{ENDPOINT}/billing/credits", headers=headers).json())
print(requests.get(f"{ENDPOINT}/version", headers=headers).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 headers = { username: EMAIL, token: token() };
console.log(await (await fetch(`${ENDPOINT}/billing/credits`, { headers })).json());
console.log(await (await fetch(`${ENDPOINT}/version`, { headers })).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 get(path, tok string) string {
	req, _ := http.NewRequest("GET", endpoint+path, nil)
	req.Header.Set("username", email)
	req.Header.Set("token", tok)
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)
	return string(body)
}

func main() {
	tok := token()
	fmt.Println(get("/billing/credits", tok))
	fmt.Println(get("/version", tok))
}
```
</CodeGroup>

## Response

`GET /billing/credits` returns your balance as a JSON string:

```json
"982.00"
```

`GET /version` returns the API version as a JSON string:

```json
"2.3.0"
```
