• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

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