• 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.

Question Connexion by API-REST

Pierre Ringenbach

New Pleskian
Server operating system version
Ubuntu 22.04
Plesk version and microupdate number
18.0.66 #2
Hi,
I'm learning how to manage my plesk users with the API (to do it automatically from another site), but, if I run my query, the 401 error still appears.
Do you have any ideas to solve this?

This is my request PHP :

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST['name'];
$email = $_POST['email'];

// Générer un mot de passe aléatoire
$password = bin2hex(random_bytes(8)); // Génère un mot de passe de 16 caractères

// Informations de l'API Plesk
$plesk_api_url = "https://domain:8443/api/v2/clients";
$api_key = "Key_API";

// Données à envoyer à l'API Plesk
$data = [
"name" => $name,
"email" => $email,
"password" => $password
];

// Configuration de la requête cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $plesk_api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"X-API-Key: $api_key"
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

// Exécution de la requête
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if ($http_code == 201) {
echo "Utilisateur créé avec succès!<br>";
echo "Nom: $name<br>";
echo "Email: $email<br>";
echo "Mot de passe: $password<br>";
} else {
echo "Erreur lors de la création de l'utilisateur. Code HTTP: $http_code<br>";
echo "Réponse: $response";
}

curl_close($ch);
}
?>

And here is the site's response :
1741254308376.png
I have nothing in the F12 console

Thank you for your help
 
A 401 error means that authentication failed. Pay attention when generating an API that you specify the right IP address, which should be the IP from which you're trying to access the Plesk server. Lastly make sure there are no access restrictions for the API (there are non by default), more information can be found here: Restricting Remote Access via Plesk API

Hope this helps.
 
Yes, but I don't have other restrictions for the API :
1741268205023.png

For this line "$plesk_api_url = "https://domain:8443/api/v2/clients";" I use a Domain name pointed at IP address, it's necessary write an IPv4 of server ?

The Domain name used is a domain name use of plesk panel, is good ?
 
when I search a little how to find my key to control, they bring me back here where I can regenerate my key.
However if we look here, I only have this interface. Do you know how I can regenerate my key from here?
1741275470379.png
for the moment I was looking for my key with this command, but this key changes every time I do the command and when refreshing my code, the error remains there.
 
Last edited by a moderator:
@Pierre Ringenbach please be careful with any information you post here! Your previous post your screenshot showed the root login credentials for your server (a moderator removed the screenshot for you). Please remember that this is a public forum, anyone can view anything that's gets posted here. As security precaution I highly recommend that you change your servers root password.

Could the key be the reason for the error?
Yes, that's very likely the issue.

Where can I check which one is correct?
You can view all current API Secret keys via SSH running the plesk bin secret_key --list command. Alternatively you can also use the Keychain for API Secret Keys extension to manage your secret keys.

Note that (like I mentioned in my previous post) if you generate a API secret key, you need to supply the IP address from which the API call to the Plesk server is made. The API secret keys are bound to the request IP address. If you need unrestricted access, you can use basic auth instead (but that's a less secure method).
 
Back
Top