• Halloween is coming! To celebrate the occasion, we dusted off a couple of old skins, and even created a brand new one (Pixel).
    To get into the festive spirit, install the Skins extension.
  • The new Python extension is now available. It allows customers to deploy and manage WSGI-based Python applications on their websites directly from Plesk.
  • The Plesk Mobile apps for iOS and Android and the Plesk Mobile Center extension have been deprecated, and are no longer available for new installations. In Plesk Obsidian 18.0.84, the Plesk Mobile Center extension will be removed from servers during the upgrade, and the Plesk Mobile apps will lose their server management features.
  • The Social Login extension has been deprecated and will be removed in Plesk Obsidian 18.0.84. After that, it will no longer be possible to log in to Plesk with a Google, Facebook, GitHub account, or with a passkey. Plesk usernames and passwords, as well as logging in with a WebPros Account, are not affected.

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