Billing systems and other tools that manage cPanel servers do their work through the WHM API, the interface that lets code create accounts, change plans and edit DNS. An admin does the same jobs by hand in WebHost Manager, cPanel’s server-level panel. The API works, but it has rough edges. Responses differ between WHM API 1 and API 2 calls, some calls report success and then fail later, and a multi-step change can stop halfway because nothing rolls it back. The answer is to choose a pattern for each job and make every call safe to retry. Push (your system calls WHM directly) when a change must land fast; poll (your system reads WHM on a schedule and corrects any drift) when staying correct matters more than speed.
The trade-off
Push pattern: external system calls WHM API directly to create/modify state. Simple, low latency, but the caller has to handle WHM-specific failure modes (timeouts, partial success, async-completion).
Poll pattern: WHM is the source of truth, external system reads via API and reconciles. More resilient (if you miss a poll, the next one catches up), but slower to propagate changes.
Webhook/event-driven: WHM doesn’t have a great webhook story natively. Some operators run a custom log tailer to convert WHM events into webhook-shaped messages. More work to build, but lower latency than polling.
How to decide
- Account provisioning from a billing system? Push with a polling fallback. The billing system tries the push; a reconciliation job runs every 15m to catch missed creates.
- DNS edits from a different control plane? Push. DNS propagation latency is already high; polling adds more.
- Inventory reporting (what’s deployed, what’s healthy)? Poll. The data doesn’t need to be real-time; the resilience matters.
- Bulk operations (plan changes, mass migrations)? Always batch with explicit progress tracking. WHM API calls don’t compose into transactions — partial failure is real.
- Cross-server operations? Push to each server independently; reconcile state via poll. Never assume a multi-server change is atomic.
What to do
- Use API tokens with minimum-required privileges. Don’t script with the root account password.
- Always check the
metadata.resultfield, not just HTTP status. WHM frequently returns HTTP 200 withmetadata.result=0(failure). - Build idempotency in the caller. WHM does not deduplicate retries; if you call
createaccttwice with the same username, the second one fails with “account exists” — which your code should treat as success-equivalent for the retry case. - Don’t script destructive operations (account deletion, terminate, db drop) without explicit human confirmation in the workflow. The automation failure mode for these is “we deleted production”.
- Log every API call with the response. When automation goes wrong, the only way back is the log of what was sent.
- Test the timeout behaviour. WHM operations can take minutes (account creation with large existing data); set client timeouts longer than you think, or use the async pattern.
- For multi-server fleets, use a queue (Redis, SQS, RabbitMQ) between the source-of-truth system and the WHM calls — buffers against transient WHM failures.
For deployment-side automation, Stack Harbor builds and operates WHM API integrations under deployment management.