Billing integration
This page is for developers of billing systems (WHMCS, in-house billing, or others) who want to automate the lifecycle of hosting services in MoorCP Shared: connection test, packages, account creation, suspend, package change, terminate, usage, SSO to the client panel, and webhooks.
Flow overview
Billing MoorCP Shared
─────── ─────────────
GET /v1/billing/capabilities ───────▶ version, features, allowed servers
POST /v1/packages ───────▶ billing-owned package (optional)
POST /v1/accounts ───────▶ 202 {account, job account.provision}
◀─────── webhook account.provision.succeeded
POST /v1/accounts/{id}/client-login ───▶ one-time SSO link
POST /v1/accounts/{id}/suspend ───────▶ job account.suspend
PUT /v1/accounts/{id}/package ───────▶ job account.change_package
POST /v1/accounts/{id}/terminate ──────▶ job account.terminate / account.purge
GET /v1/usage/accounts ───────▶ disk, inodes, bandwidth of all accountsPreparation
The panel admin creates an API key with the
billingrole and an owner, for examplemybilling, plus an allowlist of the billing server's IPs. See Authentication and API keys.If needed, the admin limits the servers the key may use with
serverIds, and sets server locations:bashcurl -sS -X PATCH https://panel.example.com:8443/v1/servers/SERVER_ID \ -H "X-API-Key: ADMIN_API_KEY" \ -H "Content-Type: application/json" \ -d '{"location": "Jakarta"}'Billing stores the base URL
https://panel.example.com:8443/v1and the billing key.
Connection test and server choice
GET /v1/billing/capabilities can be called by any billing key, including scoped keys. Use it as the "Test connection" button in billing.
curl -sS https://panel.example.com:8443/v1/billing/capabilities \
-H "X-API-Key: API_KEY"| Field | Content |
|---|---|
apiVersion, basePath, basePathAliases, panelVersion | API version (v1), base path (/v1), aliases (/api/v1), panel version |
owner | Owner of the billing key |
features | Active features, for example clientSso, deepLink, packagesWrite, ownerWebhooks, usageBulk, billingService, dns, softaculous |
deepLinkSections | Sections usable in SSO links |
phpVersions | Union of PHP versions on the servers the key may use |
servers | Server list: id, name, location, status, acceptingAccounts, accountsLeft, diskFreeMb, phpVersions, and reasons when it does not accept accounts |
Billing keys cannot read the server list through /v1/servers. Use servers from capabilities to show location choices to customers.
TIP
When creating an account, serverId may be left empty. The panel then picks the active server with the lowest relative load that passes the capacity rules (automated placement). Keys with serverIds are only placed on servers in that list.
Packages
Billing keys can use admin-made packages and can create their own. Packages created by a billing key are only visible to, and editable by, the same owner.
| Action | Endpoint | Notes |
|---|---|---|
| List | GET /v1/packages?billingId=prod-1 | Admin packages and the owner's packages. billingId is an optional filter. |
| Create | POST /v1/packages | Idempotency-Key required. Name and billingId are unique per owner. |
| Update | PUT /v1/packages/{id} | Idempotency-Key required. Reapplied to every account on the package through jobs, unless ?apply=0 is set. |
| Delete | DELETE /v1/packages/{id} | 409 cp.package_in_use while accounts that are not terminated still use it |
Creating a package:
curl -sS -X POST https://panel.example.com:8443/v1/packages \
-H "X-API-Key: API_KEY" \
-H "Idempotency-Key: pkg-prod-1-v1" \
-H "Content-Type: application/json" \
-d '{
"name": "Business Hosting",
"billingId": "prod-1",
"limits": {"CPUPercent": 100, "MemoryMB": 1024, "DiskMB": 10240, "Inodes": 300000, "BandwidthMB": 102400},
"quotas": {"Domains": 5, "Subdomains": 20, "Databases": 10, "Mailboxes": 25, "FTPAccounts": 5, "CronJobs": 10},
"features": {"SSH": true, "Softaculous": true, "Git": true},
"allowedPhpVersions": ["8.2", "8.3"]
}'PUTreplacesname,billingId,limits,quotas,features,allowedPhpVersions, anddefaultAccess. The 202 response contains the package and a list ofaccount.change_packagejobs, one per active or suspended account.PUT /v1/packages/{id}?apply=0only saves the package, and the job list is empty. Existing accounts get the new limits the next time the package is applied to them, for example on a package change or a later update withoutapply=0. In the admin GUI, the same choice is under Packages › Edit: Also update accounts on this package now, on by default.- Delete is refused with 409
cp.package_in_usewhile accounts that are not terminated still use the package. Move those accounts to another package or terminate them first. - Admin packages and other owners' packages answer 404 on update and delete.
- Delete is soft: terminated accounts keep referring to the package, while its name and
billingIdcan be reused.
The full list of limits and features is in Package features and limits.
Creating an account
curl -sS -X POST https://panel.example.com:8443/v1/accounts \
-H "X-API-Key: API_KEY" \
-H "Idempotency-Key: order-10042" \
-H "Content-Type: application/json" \
-d '{
"username": "jane",
"packageId": "PACKAGE_ID",
"primaryDomain": "myshop.com",
"email": "jane@example.com",
"billingClientId": "1001",
"billingServiceId": "svc-10042",
"phpVersion": "8.3"
}'| Field | Required | Content |
|---|---|---|
username | yes | Lowercase letters and digits, starting with a letter, 3–16 characters |
packageId | yes | An admin package or a package of the owner |
primaryDomain | yes | The account's primary domain |
billingClientId | yes, for billing keys | Client ID in billing (max 64 characters) |
billingServiceId | no | Hosting service ID in billing (max 64). One client can have many services. |
email | no | Owner contact email (notifications, app admin email) |
serverId | no | Empty = automated placement |
phpVersion | no | Initial PHP version |
The 202 response contains account (status provisioning) and job (account.provision). The account is ready once the job succeeded; the account status then becomes active. Once the account is active, the panel creates the primary domain website right away (job website.provision, document root public_html). The www.<domain> alias is only added automatically for apex domains, for example myshop.com, not for subdomains.
Refusals billing must handle:
| HTTP | Code | Cause |
|---|---|---|
| 400 | cp.account_invalid | Validation failed |
| 402 | cp.license_limit | Panel license inactive, or the license account limit is reached |
| 402 | cp.license_locked | The panel license has expired and its grace period is over; the API is locked until the license is renewed |
| 404 | Package missing, deleted, or owned by another owner | |
| 409 | cp.account_conflict | Username already used, or domain already owned by another account |
| 409 | cp.server_not_ready | Server not active yet, or in maintenance |
| 409 | cp.capacity_exceeded | No server passes the capacity rules |
| 409 | cp.idempotency_mismatch | Idempotency-Key reused with a different body |
TIP
Use the order ID as the Idempotency-Key. If billing times out and repeats the request, the panel returns the same account and job instead of creating a second account.
Finding accounts
| Need | Endpoint |
|---|---|
| All accounts of the owner | GET /v1/accounts |
| Accounts of one client | GET /v1/accounts?billingClientId=1001 |
| Account of one service | GET /v1/accounts?billingServiceId=svc-10042 |
| Details | GET /v1/accounts/{id} |
Account statuses: provisioning, active, management-disabled, suspended, terminating, terminated.
Account lifecycle
All operations below are provisioning: the billing key is enough, without X-Billing-Client-ID. Except for changing the contact email, they all return a job and require Idempotency-Key.
| Action | Endpoint | Body | Job |
|---|---|---|---|
| Suspend | POST /v1/accounts/{id}/suspend | {"reason": "..."} (required) | account.suspend |
| Unsuspend | POST /v1/accounts/{id}/unsuspend | {"reason": "..."} (optional) | account.unsuspend |
| Change package | PUT /v1/accounts/{id}/package | {"packageId": "..."} | account.change_package |
| Terminate | POST /v1/accounts/{id}/terminate | {"reason": "...", "graceDays": 14} | account.terminate or account.purge |
| Change contact email | PUT /v1/accounts/{id}/contact | {"email": "..."} |
Suspend
Suspend shows a suspension page on the websites, stops PHP, locks the database users, and expires the account's Linux login.
curl -sS -X POST https://panel.example.com:8443/v1/accounts/ACCOUNT_ID/suspend \
-H "X-API-Key: API_KEY" \
-H "Idempotency-Key: suspend-INV-2026-0042" \
-H "Content-Type: application/json" \
-d '{"reason": "Invoice INV-2026-0042 unpaid"}'An account status that does not allow suspend is answered with 409 cp.account_bad_state.
Change package
curl -sS -X PUT https://panel.example.com:8443/v1/accounts/ACCOUNT_ID/package \
-H "X-API-Key: API_KEY" \
-H "Idempotency-Key: upgrade-10042-pro" \
-H "Content-Type: application/json" \
-d '{"packageId": "NEW_PACKAGE_ID"}'Limits, quotas, and the PHP pool are reapplied on the server.
Terminate
- With
graceDaysabove 0, the account is locked right away (statusterminating) and its data is deleted automatically after the grace period. The default grace period is 14 days (the admin can change it). - With
graceDays: 0, the purge is scheduled right away and the response contains anaccount.purgejob. The purge runs on the next sweep (at most about 1 hour). - Repeated calls, including for an account already
terminating, return the same purge job. A purge is never scheduled twice.
curl -sS -X POST https://panel.example.com:8443/v1/accounts/ACCOUNT_ID/terminate \
-H "X-API-Key: API_KEY" \
-H "Idempotency-Key: terminate-10042" \
-H "Content-Type: application/json" \
-d '{"reason": "Service cancelled", "graceDays": 0}'DANGER
Purge deletes the account's home, websites, databases, and email from the server. This cannot be undone. Use a grace period if the customer might come back.
Client operations on behalf of customers
Besides provisioning, billing can run client operations (websites, databases, email, DNS, files, backups, and more) on behalf of the customer signed in to the billing client area. Requirements:
- The
X-Billing-Client-IDheader matches the account'sbillingClientId. Missing header: 400cp.billing_client_required. Mismatch: 404. - "Manage from billing" is on. If the admin turns it off, the account status becomes
management-disabledand client operations are refused with 403cp.billing_management_disabled. Provisioning still works, so billing can still suspend for non-payment. Client login links, client password and 2FA resets, and contact changes are refused with the same code while management is disabled. - The account is not suspended, terminating, or terminated. Otherwise: 403
cp.account_inactive. Job history and activity can still be read.
curl -sS https://panel.example.com:8443/v1/accounts/ACCOUNT_ID/overview \
-H "X-API-Key: API_KEY" \
-H "X-Billing-Client-ID: 1001"Website, job, and audit lists must include ?accountId=. Without it: 400 cp.account_required.
Changing the primary domain
POST /v1/accounts/{id}/primary-domain changes the account's primary domain together with its primary domain website, like Modify Account in cPanel. For billing keys this is a client operation (scope websites), so X-Billing-Client-ID is required.
curl -sS -X POST https://panel.example.com:8443/v1/accounts/ACCOUNT_ID/primary-domain \
-H "X-API-Key: API_KEY" \
-H "X-Billing-Client-ID: 1001" \
-H "Content-Type: application/json" \
-d '{"domain": "mynewshop.com"}'- The 202 response contains
old,new,websiteId, andjob(website.provision, the vhost is reapplied). - The
www.<old>alias becomeswww.<new>when the new domain is an apex domain. Other aliases, addon domains, and subdomains stay. - If the website has a Let's Encrypt certificate, a new certificate is requested right after.
- The document root, files, databases, email, and DNS zone of the old domain are not touched. A zone for the new domain is created when panel DNS is enabled.
- Refused with 400
cp.website_invalidfor an invalid domain or a subdomain of the current primary domain, and with 409cp.domain_conflictwhen the domain is used by another account or another website of this account. An account or website that is notactiveyet is refused with 409cp.account_not_ready. - The domain in billing does not change. Update it in your billing system yourself.
- Audited as
account.primary_domain.
Routes that stay admin-only and are refused with 403 cp.forbidden for billing keys:
- servers, DNS templates, cluster, and nameserver nodes, migration, configuration, staff, API keys, secrets, overview, and alerts;
- account access toggles (
PUT /access), billing owner (PUT /billing), backup policy, restore tests, mailbox send limits and blocks, and the account IPv6 setting (/ipv6).
Bulk usage
GET /v1/usage/accounts returns the usage of all the owner's accounts in pages:
curl -sS "https://panel.example.com:8443/v1/usage/accounts?limit=200" \
-H "X-API-Key: API_KEY"| Per-account field | Content |
|---|---|
accountId, username, status, packageId | Account identity |
billingClientId, billingServiceId | IDs in billing |
diskMb, diskLimitMb, inodes, inodesLimit | Sample from the last 24 hours and its limits |
bandwidthMb, bandwidthLimitMb | Bandwidth for the current month and its limit (0 = unlimited) |
bandwidthError | Set when some websites could not be counted |
visits, visitsLimit, visitsExceeded | Visits in the current month (daily unique visitors of all websites, bots excluded; null when statistics are not available), the package limit (0 = unlimited), and whether it is exceeded. The limit is reported only, not enforced. |
sampledAt | Sample time |
- Sorted by account ID. Continue with
cursor=<nextCursor>until there is nonextCursor.limitis at most 200. - Bandwidth is computed from access logs and cached for 15 minutes per account.
bandwidth=0skips it to go faster;bandwidthMbis thennull. - Terminated accounts are not included.
SSO to the client panel
Billing opens the client panel for a customer with a one-time link:
curl -sS -X POST https://panel.example.com:8443/v1/accounts/ACCOUNT_ID/client-login \
-H "X-API-Key: API_KEY" \
-H "Content-Type: application/json" \
-d '{"section": "dns", "target": "myshop.com"}'{"url": "https://panel.example.com:2083/login/sso/TOKEN", "expiresAt": "2026-11-09T03:01:00Z"}Redirect the customer's browser to url within 60 seconds. Sections and targets are described in SSO and deep links.
Billing can also open the database managers directly:
| Endpoint | For |
|---|---|
POST /v1/accounts/{id}/databases/phpmyadmin | phpMyAdmin (MariaDB) |
POST /v1/accounts/{id}/pgsql/adminneo | AdminNeo (PostgreSQL). 409 cp.adminneo_no_database when the account has no PostgreSQL database yet. |
Both are client operations, so X-Billing-Client-ID is required.
Per-owner webhooks
Billing keys can register their own webhooks with POST /v1/webhooks, so billing does not need to poll to learn that an account is active or a suspend worked.
curl -sS -X POST https://panel.example.com:8443/v1/webhooks \
-H "X-API-Key: API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "billing", "url": "https://billing.example.com/moorcp/hook", "events": ["account.*", "*.failed"]}'Webhooks owned by a billing key:
- only receive events for accounts with the same
billingOwner(job events and account alerts). Events without an account, such as server alerts, are not sent; - must use
httpsand must not point to an internal network (localhost, private IPs, link-local such as169.254.169.254,*.internal); - can only be viewed, changed, deleted, tested, and redelivered by the same owner.
Events carry account.billingClientId and account.billingServiceId, so billing can match the service directly. Payload format and signature verification are in Outgoing webhooks.
Complete lifecycle example
This example uses shell variables to keep it easy to follow.
U=https://panel.example.com:8443/v1
K=API_KEYTest the connection and pick a server:
bashcurl -sS "$U/billing/capabilities" -H "X-API-Key: $K" | jq '.servers[] | {id, name, location, acceptingAccounts}'Find the package by the product ID in billing:
bashcurl -sS "$U/packages?billingId=prod-1" -H "X-API-Key: $K" | jq -r '.[0].ID'Create the account when the order is paid:
bashcurl -sS -X POST "$U/accounts" -H "X-API-Key: $K" \ -H "Idempotency-Key: order-10042" -H "Content-Type: application/json" \ -d '{"username":"jane","packageId":"PACKAGE_ID","primaryDomain":"myshop.com","billingClientId":"1001","billingServiceId":"svc-10042"}'Wait for the
account.provision.succeededwebhook, or poll the job:bashcurl -sS "$U/jobs/JOB_ID" -H "X-API-Key: $K" | jq -r .statusThe customer clicks "Log in to panel" in billing:
bashcurl -sS -X POST "$U/accounts/ACCOUNT_ID/client-login" -H "X-API-Key: $K" | jq -r .urlThe invoice is overdue, suspend:
bashcurl -sS -X POST "$U/accounts/ACCOUNT_ID/suspend" -H "X-API-Key: $K" \ -H "Idempotency-Key: suspend-INV-0042" -H "Content-Type: application/json" \ -d '{"reason":"Invoice INV-0042 unpaid"}'The invoice is paid, unsuspend:
bashcurl -sS -X POST "$U/accounts/ACCOUNT_ID/unsuspend" -H "X-API-Key: $K" \ -H "Idempotency-Key: unsuspend-INV-0042"The customer upgrades:
bashcurl -sS -X PUT "$U/accounts/ACCOUNT_ID/package" -H "X-API-Key: $K" \ -H "Idempotency-Key: upgrade-10042-pro" -H "Content-Type: application/json" \ -d '{"packageId":"PRO_PACKAGE_ID"}'Daily usage sync:
bashcurl -sS "$U/usage/accounts?limit=200" -H "X-API-Key: $K" | jq '.accounts[] | {billingServiceId, diskMb, bandwidthMb}'The service is cancelled, terminate with a 7-day grace period:
bashcurl -sS -X POST "$U/accounts/ACCOUNT_ID/terminate" -H "X-API-Key: $K" \ -H "Idempotency-Key: terminate-10042" -H "Content-Type: application/json" \ -d '{"reason":"Service cancelled","graceDays":7}'
Binding existing accounts to billing
Accounts created by staff or migrated from cPanel have no billing owner yet. An admin binds them with:
curl -sS -X PUT https://panel.example.com:8443/v1/accounts/ACCOUNT_ID/billing \
-H "X-API-Key: ADMIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"billingOwner": "mybilling", "billingClientId": "1001", "billingServiceId": "svc-10042", "reason": "Bind to billing"}'billingClientId and reason are required. A billingServiceId that is not sent is left unchanged. An empty owner detaches the account from billing. Only admins can move an account's billing owner.
Audit
Billing key requests are recorded with the actors billing-api and apikey:<prefix>, together with the account acted on. GET /v1/audit?accountId= from a billing key returns compact entries (action, objectType, objectId, result, actorKind, occurredAt), suitable for a "Recent activity" view in the billing client area.
Testing the integration
The billing Postman collection runs the whole flow above, including the refusal cases. See Postman collection.
