• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

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