Get the domains of a user via the API

ravgrg

Verified User
Joined
Mar 9, 2024
Messages
11
Hello
How to get the user domains list? I want to detect if the user has domains or not via the API.

When I try to use the user account and password I get this error:
error=1&text=You%20cannot%20execute%20that%20command&details=The%20request%20you%27ve%20made%20cannot%20be%20executed%20because%20it%20does%20not%20exist%20in%20your%20authority%20level

I have a reseller account, how do I get the list of domains of users with the reseller account? because the get domains on the user level do not work.

My code:

// Extract the hostname from the server
$hostnameParts = explode('.', $server->hostname);
$hostname = $hostnameParts[0];
// DirectAdmin API credentials
$apiUrl = 'https://' . $server->hostname . ':2222';
// Get DirectAdmin username and password for the service
$user= $service->username; // username
$password= decrypt($service->password); // User password
$serviceUsername = $service->username; // Username
// API endpoint to list domains
$endpoint = '/CMD_API_SHOW_USER_DOMAINS';
// Initialize cURL session
$ch = curl_init();
// Set cURL options
curl_setopt($ch, CURLOPT_URL, $apiUrl . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$user:$password");
// Execute cURL request
$response = curl_exec($ch);
// Parse the response
$domains = json_decode($response, true);
print_r($response);
// If domains found, exit the hook
if (!empty($domains)) {
return;
}
 
Back
Top