cPanel webhooks allow you to automate tasks, trigger actions, and integrate external applications when specific events occur in cPanel or WHM. This is useful for real-time monitoring, automation, and API integrations.
To set up a webhook, you must use WHM's API.
Run the following command in SSH to create a webhook:
whmapi1 create_user_webhook url='https://yourserver.com/webhook-handler.php' event='Account::Create'
Replace https://yourserver.com/webhook-handler.php with your webhook URL.
This webhook will trigger every time a new cPanel account is created.
To see all active webhooks:
whmapi1 list_user_webhooks
This will display all registered webhooks, their URLs, and events.
To delete a webhook:
whmapi1 delete_user_webhook url='https://yourserver.com/webhook-handler.php' event='Account::Create'
This removes the webhook from WHM.
cPanel & WHM support webhooks for various events, such as:
| Event Name | Trigger Description |
|---|---|
| Account::Create | When a new cPanel account is created |
| Account::Remove | When a cPanel account is deleted |
| Domain::Create | When a new domain is added |
| Email::Create | When a new email account is created |
| Database::Create | When a new MySQL database is created |
You can create webhooks for any of these events!
If you set up a webhook, you need a script to handle the incoming request.
Create a webhook-handler.php file:
<?php
// Read webhook data
$data = json_decode(file_get_contents('php://input'), true);
// Log the webhook request
file_put_contents('webhook.log', print_r($data, true), FILE_APPEND);
// Respond to cPanel
http_response_code(200);
echo json_encode(["status" => "received"]);
?>
This logs webhook events and responds to cPanel.
Deploy this script on your server and update the webhook URL in WHM.
| Action | Command/API |
|---|---|
| Create a Webhook | whmapi1 create_user_webhook url='URL' event='EventName' |
| List All Webhooks | whmapi1 list_user_webhooks |
| Delete a Webhook | whmapi1 delete_user_webhook url='URL' event='EventName' |
| Handle Webhook Requests | Create a PHP webhook handler |
Now you can automate cPanel tasks with webhooks!