• 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.

Resolved Need help adding a customer with a service plan using with REST Api/CLI method

ajtaylordev

New Pleskian
Hello, so I am in the process of creating a hosting website. I'm fairly new to using APIs but I have managed to successfully connect and create a user using PHP/curl.
I'll just show my code as its probably a better way to show you where I am up to:
// CREATE NEW CUSTOMER //

$url = 'https://example.com/api/v2/clients';
$data = array(
'name' => 'John Smith',
'company' => 'Plesk',
'login' => 'john-unit-test',
'status' => '0',
'email' => '[email protected]',
'locale' => 'en-US',
'owner_login' => 'admin',
'external_id' => 'link:12345',
'description' => 'Nice Guy',
'password' => 'changeme1Q**',
'type' => 'customer'
);

$payload = json_encode($data);

$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[] = 'Content-Type: application/json';
$headers[] = 'Accept: 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);
So that above bit works fine, I can create a customer and they appear in my Plesk admin panel.
Now I want them to be able to only have the service plan that they have paid for. I have tried a few things, this is the closest I've got using cli method:
// ADD SUBSCRIPTION PLAN TO CUSTOMER USING REST API CLI METHOD //

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

$payload = "{ \"params\": [\"--create\", \"newdomain.com\", \"-owner\", \"admin\", \"-service-plan\", \"Bronze_Package\", \"-ip\", \"82.XXX.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);
So what that above does is create a new domain, but the subscriber is admin (me) whereas I want it to be the customers username. The subscription for that customer is totally blank. Id like it to be for John Smith "newdomain.com(Bronze_Package)".
Can anybody help me?
Thanks.
 
Well, what do you know, soon after posting this I have solved my problem. Instead of having admin as the -owner variable I changed it to Johns username 'john-unit-test' and after that everything worked.

I was originally working from subscription: Subscriptions but in this document the first example states "To create a subscription for the administrator’s customer with the username jdoe based on the hosting plan “Default Domain”...
I assumed I had to leave my credentials as admin in the owner because of this.
 
Back
Top