• Hi, Pleskians! We are running a UX testing of our upcoming product intended for server management and monitoring.
    We would like to invite you to have a call with us and have some fun checking our prototype. The agenda is pretty simple - we bring new design and some scenarios that you need to walk through and succeed. We will be watching and taking insights for further development of the design.
    If you would like to participate, please use this link to book a meeting. We will sent the link to the clickable prototype at the meeting.
  • (Plesk for Windows):
    MySQL Connector/ODBC 3.51, 5.1, and 5.3 are no longer shipped with Plesk because they have reached end of life. MariaDB Connector/ODBC 64-bit 3.2.4 is now used instead.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.

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