Skip to content
Last updated

TriggerNotificationEvent

Trigger a Custom Notification Event.

Request Parameters

ParameterTypeDescriptionRequired
actionstring"TriggerNotificationEvent"Required
notification_identifierstringA unique identifier string, used as a condition when making a notification rule.Optional
titlestringThe title for the notificationOptional
messagestringThe message body for the notificationOptional
urlstringThe follow up URL for the notificationOptional
statusstringA status description for the notificationOptional
statusStylestringA formatting style for the status of the notification, currently supports "success", "danger", and "info"Optional
attributesarrayAn array of Attributes to include in the notification. Requires at least label and value parameters. Other parameters are optional. See WHMCS\Notification\NotificationAttribute.Optional

Response Parameters

ParameterTypeDescription
resultstringThe result of the operation: success or error

Example Request (CURL)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'TriggerNotificationEvent',
            // See https://developers.whmcs.com/api/authentication
            'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
            'password' => 'SECRET_OR_HASHED_PASSWORD',
            'notification_identifier' => 'custom.server.add',
            'title' => 'New Server Added',
            'message' => 'new-server.examplehost.com added as a cPanel server and is available for provisioning.',
            'url' => 'https://whmcs.example.test/admin/configservers.php?action=manage&id=3',
            'status' => 'Success',
            'statusStyle' => 'info',
            'attributes[0][label]' => 'example',
            'attributes[0][value]' => 'example',
            'attributes[0][url]' => 'https://whmcs.example.test/admin/configservers.php?action=manage&id=3',
            'attributes[0][style]' => 'success',
            'attributes[0][icon]' => 'example',
            'responsetype' => 'json',
        )
    )
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);

Example Request (Local API)

$command = 'TriggerNotificationEvent';
$postData = array(
    'notification_identifier' => 'custom.server.add',
    'title' => 'New Server Added',
    'message' => 'new-server.examplehost.com added as a cPanel server and is available for provisioning.',
    'url' => 'https://whmcs.example.test/admin/configservers.php?action=manage&id=3',
    'status' => 'Success',
    'statusStyle' => 'info',
    'attributes[0][label]' => 'example',
    'attributes[0][value]' => 'example',
    'attributes[0][url]' => 'https://whmcs.example.test/admin/configservers.php?action=manage&id=3',
    'attributes[0][style]' => 'success',
    'attributes[0][icon]' => 'example',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later

$results = localAPI($command, $postData, $adminUsername);
print_r($results);

Example Response JSON

{
    "result": "success"
}

Error Responses

Possible error condition responses include:

  • API Notification Events require a identifier string to be passed.
  • API Notification Events require a title to be provided.
  • API Notification Events require a message to be provided.

Version History

VersionChangelog
1.0Initial Version