• The APS Catalog has been deprecated and removed from all Plesk Obsidian versions.
    Applications already installed from the APS Catalog will continue working. However, Plesk will no longer provide support for APS applications.
  • Please be aware: with the Plesk Obsidian 18.0.78 release, the support for the ngx_pagespeed.so module will be deprecated and removed from the sw-nginx package.

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