• 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 Plesk Rest API executes the request twice

Master

New Pleskian
Hello,

I have a little problem when I use the "POST /domains" endpoint( Other endpoints work fine).
Here is my request in PHP :
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://myplesk.domain:8443/api/v2/domains'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"name\": \"example.com\", \"description\": \"example\", \"hosting_type\": \"virtual\", \"hosting_settings\": { \"ftp_login\": \"testt\", \"ftp_password\": \"somepassword\" },\"owner_client\": { \"id\": 38, \"login\": \"john-unit-test\", \"guid\": \"fb88e0c7-804a-4e4f-8bef-*******\", \"external_id\": \"fb88e0c7-804a-4e4f-8bef-********\" },\"ipv4\": [ \"135.181.***.***\" ],\"plan\": { \"name\": \"Unlimited\" }}"); curl_setopt($ch, CURLOPT_USERPWD, 'root' . ':' . '*********'); $headers = array(); $headers[] = 'Accept: application/json'; $headers[] = 'Content-Type: application/json'; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); $final = json_decode($ch,true); curl_close($ch);
And my problem is that the request is executed twice, once, or it executes directly and creates the domain and connects it to the customer, and the second request tells me the message: string(98) "{ "code": 1007, "message": "Incorrect name example.com. This domain name already exists." }"
But I want to get the results of the first query to save them in a database, and I can't because it only shows me the results of the second query.

If someone here has a solution :)

Regards.
 
I made some change in the querry, and it's now, working fine:
$ch2 = curl_init(); curl_setopt($ch2, CURLOPT_URL, 'yourdomain.com/api/v2/domains'); curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch2, CURLOPT_POST, 1); curl_setopt($ch2, CURLOPT_POSTFIELDS, '{ "name": "'.$domain.'", "description": "'.$domain.'", "hosting_type": "virtual", "hosting_settings": { "ftp_login": "'.$username.'", "ftp_password": "'.$password.'" },"owner_client": { "id": '.$plesk_user_id.', "login": "'.$username.'", "guid": "'.$plesk_user_guid.'", "external_id": "'.$plesk_user_guid.'" }, "ip_addresses": ["135.181.***.***"],"ipv4":["135.181.***.***"],"plan": { "name": "Unlimited" }}'); curl_setopt($ch2, CURLOPT_USERPWD, 'root' . ':' . '********'); $headers = array(); $headers[] = 'Accept: application/json'; $headers[] = 'Content-Type: application/json'; curl_setopt($ch2, CURLOPT_HTTPHEADER, $headers); $resultdomain = curl_exec($ch2); curl_close($ch2);
This one work fine, but the old one still dont work, i dont know why...

Regards
 
Your code should be:

Code:
$result = curl_exec($ch);
$final = json_decode($result,true);
curl_close($ch);
 
Back
Top