• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Question access thorugh url gives error

hamza-24

Basic Pleskian
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
 
@hamza-24, just like any other web page you'll have to upload your test.php page to the webspace of a domain where you can access it via example.com/test.php.

It looks like you're new to PHP, maybe these free PHP courses will help you beter understand how to work with PHP.
 
sorry for my lack of knowledge but I just want to understand how I can connect the API so that user creation is automated when someone signups.
really confuse din that. @Kaspar
 
Your script is connecting to API via curl - it looks OK besides the xml/json part. Now you have to place your script somewhere so it can be called.
Talking in Plesk terms, you would create a domain with PHP enabled and upload it via File manager.

So the basic setup looks like this:
1. You have an API endpoints, provided by Plesk at https://<Plesk URL or IP>:8443/api/v2/<endpoint-name>
2. You have your domain https://some-domain.com created in Plesk
3. You upload a .php file (e.g. form.php) via File manager
4. You open https://some-domain.com/form.php in your browser and can see the results of your script execution
 
Back
Top