• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

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