berth

Customers and resellers

Billing integration (WHMCS, HostBill, provisioning API)

Connect WHMCS or HostBill so orders create, suspend, upgrade and terminate subscriptions automatically, or drive the same /api/v1/provisioning/ API from your own billing system.

Updated 6 min readwhmcs · hostbill · billing · provisioning · api · ssoView as Markdown

On this page
  1. How it works
  2. Creating the provisioning token
  3. WHMCS
  4. HostBill
  5. The provisioning API
  6. Related

When customers order hosting in a billing system, the billing system should create the account, suspend it when an invoice is overdue and remove it when the contract ends. Berth has a provisioning API for exactly that, and ready-made modules for WHMCS and HostBill that use it. One service in the billing system is one subscription in Berth, identified by the service's domain.

How it works

  • The billing system authenticates with an API token that has the provisioning scope. That token can only reach /api/v1/provisioning/ and nothing else in the API, so a leaked billing token cannot touch DNS, backups or settings.
  • Every call is identified by the domain of the service. Creating is idempotent on that domain, so a retry after a timeout does not create a second account.
  • The package of a product in the billing system is the name of a package in Berth. The modules load the list of package names from the panel.
  • Every provisioning action is recorded in the audit trail like any other change.

Creating the provisioning token

Only an administrator can create a provisioning token. In the panel: Account → AI connection (the page AI connection and API keys) → Create key and choose the rights Billing. On the server:

berth token create --login admin --name whmcs --scope provisioning > whmcs-token.txt

The secret is shown once. Store it in the billing system and nowhere else; revoke it with berth token revoke or on the same page if it leaks. See REST API for tokens in general.

WHMCS

The WHMCS server module supports:

WHMCS functionWhat happens in Berth
CreateCreates the customer if needed, the subscription on the chosen package, and the domain.
Suspend / UnsuspendSuspends only that subscription: sites show the suspension page; SSH/SFTP, cron, FTP and mailboxes are closed. The customer's other services keep working.
TerminateRemoves the subscription's databases, domains (with mail and files) and the subscription; a customer left without subscriptions is removed too.
Change packageMoves the subscription to another package.
Change passwordSets the password of the customer login.
Test connectionChecks the token and shows the panel version and packages.
Single sign-onThe client area button logs the customer in to the panel without a password.
Package listThe Module Settings dropdown is filled with the panel's package names.
Usage updateDisk and traffic of every service on the server, for WHMCS usage display and billing.
Client areaA small client area template for the service.

The customer in Berth gets the login whmcs-<client id>, so the same WHMCS client with several services ends up as one customer with several subscriptions.

Setting up WHMCS

  1. Copy the Berth server module (the folder berth) into modules/servers/ of your WHMCS installation.
  2. Create the provisioning token as above.
  3. In WHMCS: System Settings → Servers → Add New Server. Choose module Berth, set the hostname to the panel's hostname, paste the token into Access Hash, and tick Secure.
  4. For each product: Module Settings → module Berth, then pick the Berth package from the list.
  5. Use Test Connection on the server to check the token.

All module calls are idempotent, so retrying a failed action from WHMCS is safe.

HostBill

The HostBill hosting module uses the same provisioning API and supports create, suspend, unsuspend, terminate, change package and change password, plus:

  • Status sync: the regular HostBill synchronisation picks up whether the account is suspended, and its usage.
  • Usage: disk and traffic of one account, or of all accounts in one call, in whole MB, for usage billing. Traffic is web traffic in and out for the current calendar month, the same figures the panel shows.
  • Single sign-on: a one-time login link for the customer, requested at the moment they click.

The customer in Berth gets the login hostbill-<client id>.

Setting up HostBill

  1. Copy the Berth module (the folder berth) into includes/modules/Hosting/ and activate it under Settings → Modules → Hosting Modules.
  2. Create a provisioning token in Berth.
  3. In HostBill: Settings → Apps → Add new App, module Berth, Hostname = the panel, Password = the token, SSL on. Fill in Port only if the panel is not on 443.
  4. For each product: Connect with App → Berth, and choose the package.

Berth requires customer passwords of at least 12 characters. When HostBill generates a shorter one at creation, the module generates a longer password and stores it on the account.

The provisioning API

Your own billing or CRM system can use the same endpoints. All requests use Authorization: Bearer <token> with a provisioning token, and request bodies must be sent as Content-Type: application/json.

Method and pathWhat it does
GET /api/v1/provisioning/testTest the connection: panel version and package names.
POST /api/v1/provisioning/accountsCreate a service: customer if needed, subscription and domain. Idempotent on the domain.
GET /api/v1/provisioning/accountsAll services with their usage.
GET /api/v1/provisioning/accounts/{domain}One service with its usage.
POST /api/v1/provisioning/accounts/{domain}/suspendSuspend this subscription only, with an optional reason.
POST /api/v1/provisioning/accounts/{domain}/unsuspendLift the suspension.
PUT /api/v1/provisioning/accounts/{domain}/planMove to another package.
POST /api/v1/provisioning/accounts/{domain}/passwordSet the password of the customer login.
POST /api/v1/provisioning/accounts/{domain}/ssoA one-time login link for the customer.
DELETE /api/v1/provisioning/accounts/{domain}Terminate: databases, domains and subscription, and the customer when nothing is left, unless ?keep_customer=true.

Examples

Create a service:

curl -s https://panel.example.nl/api/v1/provisioning/accounts \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"domain":"acme.nl","plan":"basis",
       "customer":{"login":"acme","name":"Acme","email":"info@acme.nl","password":"…"}}'

The customer object also accepts reseller, to create the customer under a reseller. The answer (201) describes the service, with the same fields that GET …/accounts/{domain} returns:

FieldMeaning
createdtrue when this call created it, false when it already existed
domain, domainsThe service's domain and all domains of the subscription
customer, sysuser, planCustomer login, system user of the subscription, package name
suspended, suspend_reason, customer_suspendedSuspension state of the subscription and of the customer
disk_mb, disk_limit_mb, traffic_mb, traffic_limit_mbUsage and limits in MB; a limit of 0 is unlimited
panel_url, sftp_hostWhere the customer logs in and connects with SFTP, for the welcome mail
created_atWhen the subscription was created

Suspend with a reason, and change the package:

curl -s -X POST https://panel.example.nl/api/v1/provisioning/accounts/acme.nl/suspend \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"reason":"Invoice 2026-1042 overdue"}'

curl -s -X PUT https://panel.example.nl/api/v1/provisioning/accounts/acme.nl/plan \
  -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  -d '{"plan":"webshop"}'

Errors come back as a 4xx or 5xx status with a JSON body containing error (a message in Dutch) and request_id, which identifies the request when you report a problem.

POST …/accounts/{domain}/sso returns a URL of the form https://<panel>/sso/<token>. The link is valid for one minute and works once, and the customer arrives logged in on their dashboard. Request it when the customer clicks log in to the panel, redirect them straight away, and never store or e-mail it. Only a provisioning token, or an administrator with their own panel session, can create such a link; no other API key can, including those of extensions. Each request is logged as provisioning.sso and each use as login.sso.