Skip to content

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 ​

text
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 accounts

Preparation ​

  1. The panel admin creates an API key with the billing role and an owner, for example mybilling, plus an allowlist of the billing server's IPs. See Authentication and API keys.

  2. If needed, the admin limits the servers the key may use with serverIds, and sets server locations:

    bash
    curl -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"}'
  3. Billing stores the base URL https://panel.example.com:8443/v1 and 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.

bash
curl -sS https://panel.example.com:8443/v1/billing/capabilities \
  -H "X-API-Key: API_KEY"
FieldContent
apiVersion, basePath, basePathAliases, panelVersionAPI version (v1), base path (/v1), aliases (/api/v1), panel version
ownerOwner of the billing key
featuresActive features, for example clientSso, deepLink, packagesWrite, ownerWebhooks, usageBulk, billingService, dns, softaculous
deepLinkSectionsSections usable in SSO links
phpVersionsUnion of PHP versions on the servers the key may use
serversServer 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.

ActionEndpointNotes
ListGET /v1/packages?billingId=prod-1Admin packages and the owner's packages. billingId is an optional filter.
CreatePOST /v1/packagesIdempotency-Key required. Name and billingId are unique per owner.
UpdatePUT /v1/packages/{id}Idempotency-Key required. Reapplied to every account on the package through jobs, unless ?apply=0 is set.
DeleteDELETE /v1/packages/{id}409 cp.package_in_use while accounts that are not terminated still use it

Creating a package:

bash
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"]
  }'
  • PUT replaces name, billingId, limits, quotas, features, allowedPhpVersions, and defaultAccess. The 202 response contains the package and a list of account.change_package jobs, one per active or suspended account.
  • PUT /v1/packages/{id}?apply=0 only 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 without apply=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_use while 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 billingId can be reused.

The full list of limits and features is in Package features and limits.

Creating an account ​

bash
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"
  }'
FieldRequiredContent
usernameyesLowercase letters and digits, starting with a letter, 3–16 characters
packageIdyesAn admin package or a package of the owner
primaryDomainyesThe account's primary domain
billingClientIdyes, for billing keysClient ID in billing (max 64 characters)
billingServiceIdnoHosting service ID in billing (max 64). One client can have many services.
emailnoOwner contact email (notifications, app admin email)
serverIdnoEmpty = automated placement
phpVersionnoInitial 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:

HTTPCodeCause
400cp.account_invalidValidation failed
402cp.license_limitPanel license inactive, or the license account limit is reached
402cp.license_lockedThe panel license has expired and its grace period is over; the API is locked until the license is renewed
404Package missing, deleted, or owned by another owner
409cp.account_conflictUsername already used, or domain already owned by another account
409cp.server_not_readyServer not active yet, or in maintenance
409cp.capacity_exceededNo server passes the capacity rules
409cp.idempotency_mismatchIdempotency-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 ​

NeedEndpoint
All accounts of the ownerGET /v1/accounts
Accounts of one clientGET /v1/accounts?billingClientId=1001
Account of one serviceGET /v1/accounts?billingServiceId=svc-10042
DetailsGET /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.

ActionEndpointBodyJob
SuspendPOST /v1/accounts/{id}/suspend{"reason": "..."} (required)account.suspend
UnsuspendPOST /v1/accounts/{id}/unsuspend{"reason": "..."} (optional)account.unsuspend
Change packagePUT /v1/accounts/{id}/package{"packageId": "..."}account.change_package
TerminatePOST /v1/accounts/{id}/terminate{"reason": "...", "graceDays": 14}account.terminate or account.purge
Change contact emailPUT /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.

bash
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 ​

bash
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 graceDays above 0, the account is locked right away (status terminating) 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 an account.purge job. 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.
bash
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:

  1. The X-Billing-Client-ID header matches the account's billingClientId. Missing header: 400 cp.billing_client_required. Mismatch: 404.
  2. "Manage from billing" is on. If the admin turns it off, the account status becomes management-disabled and client operations are refused with 403 cp.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.
  3. The account is not suspended, terminating, or terminated. Otherwise: 403 cp.account_inactive. Job history and activity can still be read.
bash
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.

bash
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, and job (website.provision, the vhost is reapplied).
  • The www.<old> alias becomes www.<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_invalid for an invalid domain or a subdomain of the current primary domain, and with 409 cp.domain_conflict when the domain is used by another account or another website of this account. An account or website that is not active yet is refused with 409 cp.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:

bash
curl -sS "https://panel.example.com:8443/v1/usage/accounts?limit=200" \
  -H "X-API-Key: API_KEY"
Per-account fieldContent
accountId, username, status, packageIdAccount identity
billingClientId, billingServiceIdIDs in billing
diskMb, diskLimitMb, inodes, inodesLimitSample from the last 24 hours and its limits
bandwidthMb, bandwidthLimitMbBandwidth for the current month and its limit (0 = unlimited)
bandwidthErrorSet when some websites could not be counted
visits, visitsLimit, visitsExceededVisits 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.
sampledAtSample time
  • Sorted by account ID. Continue with cursor=<nextCursor> until there is no nextCursor. limit is at most 200.
  • Bandwidth is computed from access logs and cached for 15 minutes per account. bandwidth=0 skips it to go faster; bandwidthMb is then null.
  • Terminated accounts are not included.

SSO to the client panel ​

Billing opens the client panel for a customer with a one-time link:

bash
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"}'
json
{"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:

EndpointFor
POST /v1/accounts/{id}/databases/phpmyadminphpMyAdmin (MariaDB)
POST /v1/accounts/{id}/pgsql/adminneoAdminNeo (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.

bash
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 https and must not point to an internal network (localhost, private IPs, link-local such as 169.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.

bash
U=https://panel.example.com:8443/v1
K=API_KEY
  1. Test the connection and pick a server:

    bash
    curl -sS "$U/billing/capabilities" -H "X-API-Key: $K" | jq '.servers[] | {id, name, location, acceptingAccounts}'
  2. Find the package by the product ID in billing:

    bash
    curl -sS "$U/packages?billingId=prod-1" -H "X-API-Key: $K" | jq -r '.[0].ID'
  3. Create the account when the order is paid:

    bash
    curl -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"}'
  4. Wait for the account.provision.succeeded webhook, or poll the job:

    bash
    curl -sS "$U/jobs/JOB_ID" -H "X-API-Key: $K" | jq -r .status
  5. The customer clicks "Log in to panel" in billing:

    bash
    curl -sS -X POST "$U/accounts/ACCOUNT_ID/client-login" -H "X-API-Key: $K" | jq -r .url
  6. The invoice is overdue, suspend:

    bash
    curl -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"}'
  7. The invoice is paid, unsuspend:

    bash
    curl -sS -X POST "$U/accounts/ACCOUNT_ID/unsuspend" -H "X-API-Key: $K" \
      -H "Idempotency-Key: unsuspend-INV-0042"
  8. The customer upgrades:

    bash
    curl -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"}'
  9. Daily usage sync:

    bash
    curl -sS "$U/usage/accounts?limit=200" -H "X-API-Key: $K" | jq '.accounts[] | {billingServiceId, diskMb, bandwidthMb}'
  10. The service is cancelled, terminate with a 7-day grace period:

    bash
    curl -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:

bash
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.

See also ​

MoorCP Shared, a shared hosting panel for server fleets.