• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

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