• Dear Pleskians! The Plesk Forum will be undergoing scheduled maintenance on Monday, 7th of July, at 9:00 AM UTC. The expected maintenance window is 2 hours.
    Thank you in advance for your patience and understanding on the matter.

Question Error 200 delete User API REST

Pierre Ringenbach

New Pleskian
Server operating system version
Ubuntu 22.04
Plesk version and microupdate number
18.0.67
Hello,
I have a problem with my program that gives me a vague error.
I use REST API with a key generated with the extension "Keychain for API Secret Keys"

Everything works well (user creation, information retrieval, change account status) but it is impossible to delete the user.
Instead, it shows me the following error:
Error deleting user. HTTP Code: 200
API Response: { "id": 11, "created": "2025-03-07", "name": "Pierre", "company": "", "login": "[email protected]", "status": 1, "email": "[email protected]", "locale": "", "guid": "96s24355-3898-4055-982c-191df9ee9a32", "external_id": "", "description": "", "type": "customer" }
(API response data has been anonymized.)

Regarding the code I currently have, here it is:
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Supprimer un utilisateur Plesk</title>
</head>
<body>
<h1>Supprimer un utilisateur Plesk</h1>
<form action="delete_user.php" method="POST">
<label for="user_id">ID de l'utilisateur :</label>
<input type="text" id="user_id" name="user_id" required>
<button type="submit">Supprimer</button>
</form>
</body>
</html>
<?php
if (isset($_POST['user_id'])) {
$user_id = $_POST['user_id'];

// URL de l'API Plesk pour obtenir les informations d'un utilisateur
include'./settings/api_connect.php';
$url = $api_link . '/clients/' . $user_id;

// Initialisation de cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'X-API-Key: ' . $api_key // Utilisation de la clé API
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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

// Fermeture de la session cURL
curl_close($ch);

// Vérification de la réponse
if ($http_code == 204) {
echo "L'utilisateur avec l'ID {$user_id} a été supprimé avec succès.";
} else {
echo "Erreur lors de la suppression de l'utilisateur. Code HTTP : {$http_code}";
echo "<br>Réponse de l'API : " . htmlentities($response);
}
} else {
echo "Aucun ID d'utilisateur n'a été fourni.";
}
?>
if anyone has the solution, I'm interested.
I really wonder why it refuses to delete the user and instead shows me his info.

Thank you very much for your help
 
An 200 status response code actually means that the request has been successful. Doesn't the customer get deleted?
 
Back
Top