Cpanel Email Password Change From WHM API

55 views Asked by At

I am not able to change Cpanel Email Password from the whm API.

Official WHM API Documents providing the : https://{host}:{port}/execute/Email/passwd_pop

but when I try this I am getting error:

Error: Unknown app (“passwd_pop”) requested for this version (1) of the API.

Please give me a solution for this.

This is my PHP code:

<?php

// Set the WHM API endpoint URL
$whmApiEndpoint = 'https://host/json-api/passwd_pop';

// Set the API token (generated in WHM)
$apiToken = 'my WHM API';

// Set the email account you want to change the password for
$emailUsername = 'my Cpanel Email ';
$newPassword = 'changing the password';

// Create an array with the POST data
$postData = [
    'api.version' => 1,
    'user' => 'cpanel user name', // The cPanel username associated with the email
    'email' => $emailUsername,
    'password' => $newPassword,
];

// Initialize cURL session
$ch = curl_init($whmApiEndpoint);

// Set cURL options for the POST request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: whm root:my api',
    'Content-Type: application/x-www-form-urlencoded',
]);

// Execute the cURL request
$response = curl_exec($ch);

?>
0

There are 0 answers