- Server operating system version
- centOS 7
- Plesk version and microupdate number
- 18.0.50
i am using the folowing code for creating user using rest API
<?php
// Define Plesk API credentials
$host = 'abc.xyz.123';
$login = 'admin';
$password = '@{dQr-r3$MCiWlZ';
// Define customer details
$customerName = 'testcustomer';
$customerEmail = '[email protected]';
$customerUsername = 'customer';
$customerPassword = 'temp1234@';
// Build API request body
$requestBody = <<<EOT
<customer>
<gen_info>
<pname>{$customerName}</pname>
<email>{$customerEmail}</email>
<username>{$customerUsername}</username>
<password>{$customerPassword}</password>
</gen_info>
</customer>
EOT;
// Send API request to create customer
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://{$host}:8443/api/v2/customers");
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/xml',
'Authorization: Basic ' . base64_encode("{$login}:{$password}")
));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
// Parse API response
$xml = simplexml_load_string($response);
if ($xml->xpath('//errtext')) {
echo "Error creating customer: {$xml->errtext}\n";
} else {
$customerId = $xml->id;
echo "Customer created with ID {$customerId}\n";
}
?>
but it gives me error page not found and no user is created
<?php
// Define Plesk API credentials
$host = 'abc.xyz.123';
$login = 'admin';
$password = '@{dQr-r3$MCiWlZ';
// Define customer details
$customerName = 'testcustomer';
$customerEmail = '[email protected]';
$customerUsername = 'customer';
$customerPassword = 'temp1234@';
// Build API request body
$requestBody = <<<EOT
<customer>
<gen_info>
<pname>{$customerName}</pname>
<email>{$customerEmail}</email>
<username>{$customerUsername}</username>
<password>{$customerPassword}</password>
</gen_info>
</customer>
EOT;
// Send API request to create customer
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://{$host}:8443/api/v2/customers");
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/xml',
'Authorization: Basic ' . base64_encode("{$login}:{$password}")
));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
curl_close($curl);
// Parse API response
$xml = simplexml_load_string($response);
if ($xml->xpath('//errtext')) {
echo "Error creating customer: {$xml->errtext}\n";
} else {
$customerId = $xml->id;
echo "Customer created with ID {$customerId}\n";
}
?>
but it gives me error page not found and no user is created