Connect Blesta, HostBill and other billing systems (json-api)
On this page
Besides the REST API, the server answers a /json-api/<function> interface on port 2087 with the function names many hosting billing systems use: createacct, suspendacct, changepackage and so on.
Before you start
- An administrator or reseller API token. A reseller's token works only on the reseller's accounts and within their privileges.
- Add the billing server's IP address to the Whitelisted IPs of Brute Force Protection.
Set up the billing system
- Add a server with the hosting control panel module that asks for a username and an API token.
- Hostname: the server's hostname, port
2087, with SSL. - Username: your admin or reseller username. API token: the token.
- In each product, enter the package name exactly as it is in the panel.
The request must carry the token in the Authorization header, as Bearer <token> or as sahaab <username>:<token>.
Calling a function
GET or POST https://<server>:2087/json-api/<function>?api.version=1&<parameters>
With api.version=1 the answer is:
{"metadata": {"version": 1, "reason": "OK", "result": 1, "command": "listaccts"}, "data": { ... }}
result is 1 on success, 0 on failure, with the reason in reason. Without api.version=1 the answer uses the older format that older modules expect.
Functions
| Function | What it does | Parameters |
|---|---|---|
createacct | Create an account | username, domain, plan (package name), contactemail, password |
suspendacct | Suspend | user, reason (optional) |
unsuspendacct | Unsuspend | user |
removeacct | Terminate | user |
changepackage | Change the package | user, pkg |
passwd | Change the password | user, password |
modifyacct | Change contact email, main domain or username | user, any of contactemail, domain, newuser |
listaccts | List accounts | optional search, searchtype (user, domain, owner, package, ip), searchmethod=exact |
accountsummary | One account | user |
listpkgs | Packages and their limits | — |
showbw | Bandwidth per account for a month | optional month, year, search |
create_user_session | One-time sign-in link (60 seconds) | user |
gethostname | The server's hostname | — |
version | The panel version | — |
applist | The supported functions | — |
Good to know
- If
createaccthas noplan, the token owner's first package is used. Withoutcontactemail, the token owner's email is used. It returns the account's IP and nameservers. - A package name with the reseller's username in front (
reseller1_Basic) also findsBasic. - Account details include the domain, contact email, package, owner, IP, suspension and reason, disk used and limit, and the package's limits.
- A read-only token may call only
version,applist,listaccts,accountsummary,listpkgs,showbwandgethostname.
Examples
Create an account:
curl -s -H "Authorization: Bearer $TOKEN" \
"https://server1.example.com:2087/json-api/createacct?api.version=1" \
--data-urlencode "username=shop1" \
--data-urlencode "domain=shop-example.com" \
--data-urlencode "plan=Basic" \
--data-urlencode "[email protected]" \
--data-urlencode "password=Str0ng-Passw0rd!"
Suspend:
curl -s -H "Authorization: Bearer $TOKEN" \
"https://server1.example.com:2087/json-api/suspendacct?api.version=1&user=shop1&reason=Unpaid+invoice"
Sign-in link for the customer (data.url):
curl -s -H "Authorization: Bearer $TOKEN" \
"https://server1.example.com:2087/json-api/create_user_session?api.version=1&user=shop1"
Common questions
The billing system says "Access denied". Why?
The token is wrong, expired, not allowed from that address, or the reseller lacks the privilege; the reason follows "Access denied". See API errors.
Thank you — this helps us improve the article.
Still stuck?
Ask the AI about your exact situation — it answers from this knowledge base — or contact us.
Related articles
- How to connect WHMCS to the control panel (provisioning module)
Install the WHMCS module, add the server with an API token and pick packages, so WHMCS creates, suspends, upgrades and terminates accounts.
- How to create an API token for scripts and billing
Create an API token in the admin panel or the control panel for the REST API or a billing system, copy it once, see when it was last used, and revoke it.
- How to restrict an API token (IP addresses, expiry, read only)
Limit an API token to your billing server's IP addresses, let it expire after 7 to 365 days, or make it read only, and the errors you get when a limit applies.
- API returns 401 Unauthorized, 403 or IP blocked
Fix API errors: 401 Unauthorized, expired token, address not allowed, IP blocked after failed attempts, read-only token, missing privilege and 422.