Getting started
Authentication
The HisarPay API expects an API key on every request. The key decides which mode you work in, what you can reach and which IP addresses may use it.
API keys
Send the key as a Bearer token in the Authorization header. Every request goes over HTTPS and bodies are JSON.
curl https://hisarpay.com/v1/balances \
-H "Authorization: Bearer $HISARPAY_API_KEY"const hisarpay = new HisarPay(process.env.HISARPAY_API_KEY!);
const { data } = await hisarpay.balances.retrieve();$hisarpay = new \HisarPay\HisarPay(getenv('HISARPAY_API_KEY'));
$balances = $hisarpay->balances->retrieve();client = HisarPay(os.environ["HISARPAY_API_KEY"])
balances = client.balances.retrieve()- Keys are created in the dashboard under Developers → API keys and shown only once. HisarPay stores a hash, not the key itself.
- A missing, malformed or revoked key gets
401 unauthorized. If your account is suspended, the response is403 account_not_active. - Every response carries an
X-Request-Idheader. Quote it when you contact support. If you send your own id in the same header (8–64 letters, digits,_or-), HisarPay uses it.
HTTP/1.1 401 Unauthorized
X-Request-Id: req_5f0c6c1e8a514c7e9d0e2b1f4f6a9c11
{
"error": {
"code": "unauthorized",
"message": "invalid or revoked API key",
"request_id": "req_5f0c6c1e8a514c7e9d0e2b1f4f6a9c11"
}
}Live and test mode
Keys that start with hp_live_ process real payments; keys that start with hp_test_ work in test mode. The two modes keep their data apart: test invoices, links and events never show up in live lists.
| Test (hp_test_) | Live (hp_live_) | |
|---|---|---|
| Blockchain | Not used; payments are simulated | TRON mainnet |
| Balance | Untouched; balance endpoints return an empty list | Real balance |
| Withdrawals | Not possible | With the withdrawals scope |
| Managing webhook endpoints | Not possible (403 test_key) | With the webhooks scope |
| Simulation | Yes | No (403 live_key) |
Your webhook endpoints receive events from both modes. Check the livemode field of each event to tell test events apart.
Scopes
Pick only the scopes you need when you create a key. A key that calls an endpoint outside its scopes gets 403 forbidden. Test keys can never carry the withdrawals and webhooks scopes.
| Scope | Allows |
|---|---|
read | Balances, ledger entries, events, the list of webhook endpoints, rates, coin details, status and chain lookups. |
invoices | Create, read, cancel and simulate invoices and payment links. |
webhooks | Add, change and delete webhook endpoints, rotate their signing secret and resend events. Live keys only. |
withdrawals | Single withdrawals to trusted addresses. Live keys only. |
reports | Asking for reports and downloading the files. |
The API reference lists the scope each endpoint needs.
IP allowlist
You can restrict a key to up to 20 IPv4 or IPv6 addresses or CIDR blocks (for example 203.0.113.0/24). A request from any other address is rejected with 403 forbidden. With an empty list, the key works from anywhere.
Expiry
A key can be given 30, 90, 180 or 365 days when you create it; otherwise it has no end date. We notify and e-mail you 14 and 3 days before it ends, and when it has ended. An expired key gets 401 unauthorized. Creating a live key asks for your password and second factor, and for an authenticator app or a passkey on the account.
Keeping keys safe
- Use keys on the server only; never send them to a browser or a mobile app.
- Create a separate key for each integration, so revoking one leaves the others working.
- To replace a key, create and deploy the new one first, then revoke the old one in the dashboard. Revocation is immediate.
- The dashboard’s activity log shows API requests together with the key’s prefix. If you see usage you do not recognise, revoke the key right away.