• 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 Help creating hosting type via api

ajtaylordev

New Pleskian
Hello, I can't work out where I am going wrong. Using the default details Plesk gave me it works fine, users, subscriptions, domain and hosting type. However when I use my own script with PHP variables in, everything is created fine except the domain hosting type is set to "No Hosting".

Working example with Plesk default details:
// ADD SUBSCRIPTION PLAN TO CUSTOMER USING REST API CLI METHOD //

$url = 'https://example-server.cloud/api/v2/cli/subscription/call';

$payload = "{ \"params\": [\"--create\", \"example.com\", \"-owner\", \"john-unit-test\", \"-service-plan\", \"Bronze_Package\", \"-ip\", \"82.165.XXX.XXX\", \"-login\", \"john-unit-test\", \"-passwd\", \"changeme1Q**\"]}";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/json';
$headers[] = 'X-API-Key: '.$secret_token.'';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
My example, same result apart from Hosting type is set to "No Hosting":
// ADD SUBSCRIPTION PLAN TO CUSTOMER USING REST API CLI METHOD //

$url = 'https://example-server.cloud/api/v2/cli/subscription/call';

$payload = '{ "params": ["--create", "example.com", "-owner", "'.$plesk_user.'", "-service-plan", "'.$service_plan.'", "-ip", "82.165.XXX.XXX", "-login", "'.$plesk_user.'", "-passwd", "'.$plesk_pass.'"]}';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Content-Type: application/json';
$headers[] = 'X-API-Key: '.$secret_token.'';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
The only thing really different is I have used single quotes in order to make the variables more readable. I doubt this causes issues as everything seems to be working like correct service plan, username, passwords etc...
If anybody could tell me why my code gives me "No Hosting" as the default hosting type in comparison that would be greatly appreciated. Thankyou.
 
I can't reproduce your issue. Your best bed would to double check your variables.
 
Last edited:
Thanks for your help, I went and double checked the variables. I think the problem lies in username/password. For the username it needs to be lowercase and for the password there is some sort of minimum strength required. Changing my username from 'David' to 'david' and a stronger password got it working!
Bit of a weird problem as it prior to this it was still creating the accounts, only now the 'Hosting Type' is changing and I would not have thought the two were related, maybe some sort of bug?
 
Is the username and password requirements laid out in any documentation? Ideally I would like to replicate these requirements on my website as the username and password used for my website is passed in the plesk api script. Thanks.
 
Is the username and password requirements laid out in any documentation? Ideally I would like to replicate these requirements on my website as the username and password used for my website is passed in the plesk api script. Thanks.
Yeah, a subscription user name needs to be lower case, can't start with a number and can only contain a dash or underscore as a special character. I can't find any specification about the user name in the documentation trough.

The password strength requirement can be set on Tools & Settings > Security Policy (under “Security”), and then scroll down to the “Password strength” section.
You can read more about password strength and the upcoming changes on this link: https://support.plesk.com/hc/en-us/articles/213912245
 
Last edited:
Ok cool, well I've just implemented this in my customer registration form and all is ok now. Thanks for your help to resolve this.
 
Thanks for your help, I went and double checked the variables. I think the problem lies in username/password. For the username it needs to be lowercase and for the password there is some sort of minimum strength required. Changing my username from 'David' to 'david' and a stronger password got it working!
Bit of a weird problem as it prior to this it was still creating the accounts, only now the 'Hosting Type' is changing and I would not have thought the two were related, maybe some sort of
 
Sorry, my last reply auto sent. I just wanted to say thanks, you helped me figure out my question. I was. having the same issue.
 
Back
Top