Cmd_api_domain_pointer

vespino

Verified User
Joined
Nov 21, 2017
Messages
12
I'm trying to list all domains including domain pointers using the API. I currently have the following code:

PHP:
//list users
$sock->query('/CMD_API_SHOW_USERS');
$users=$sock->fetch_parsed_body();

foreach($users['list'] as $user) {
	//get domains for user
	$sock->query(
		'/CMD_API_SHOW_USER_DOMAINS',
		array(
			'user'=>$user
		)
	);
	
	$domains=$sock->fetch_parsed_body();
	
	echo str_replace('_', '.', $domain).'<br>';
	
	//print_r($domains);
	
	foreach($domains as $domain=>$data) {
		//get domain pointers for domain
		$sock->query(
			'/CMD_API_DOMAIN_POINTER',
			array(
				'domain'=>str_replace('_', '.', $domain)
			)
		);
		
		$domain_pointers=$sock->fetch_parsed_body();
		
		print_r($domain_pointers);
	}
}

The CMD_API_DOMAIN_POINTER command however only returns "Could not execute your request" and "You do not own that domain".

Am I doing this the right way?
 
Hello,

If you see the error, then you do something wrong. It seems you should run the API call as user, not as a reseler/admin, but in behalf of the domain's owner.
 
Correct, I'm the administrator of the server so I guess I should be able to collect that data, right?
 
Is it possible to provide an example? The documentation says:

Note that you can use the "login-as" feature with the API if you want to make User Level API calls for your clients, but don't know their passwords. The way you do that is setup your API to make the User Level API call normally, but instead of using $username = "clientuser"; (since you don't know their password) you'd instead use: $username = "admin|clientuser"; and specify the admin password. This can be used for any Admin or Reseller who controls the client they're logging into. Note that an Admin can control everyone, so they can login to anyone's account with this method. A Reseller can obviously only log into their own client's accounts. You can also test this feature out at the standard DA login page.. enter the "admin|user" username instead of "admin", along with the admin password, and you'll be logged in as "user" with your browser.

But I don't seem to be able to wrap my head around this.
 
Unfortunately it's not clear to me how to go about this. Can you help me some more, maybe based on my code?
 
Your code does not have authentication part, which needs to be modified. You need to add authentication part inside the foreach loop. And the authentication part inside the loop should use login-as feature.
 
This my complete code:

PHP:
<?php
include_once 'httpsocket.php';

$sock=new HTTPSocket;
$sock->connect('ssl://fqdn', 2222);
$sock->set_login('admin', 'pass');

//list users
$sock->query('/CMD_API_SHOW_USERS');
$users=$sock->fetch_parsed_body();

foreach($users['list'] as $user) {
	//get domains for user
	$sock->query(
		'/CMD_API_SHOW_USER_DOMAINS',
		array(
			'user'=>$user
		)
	);
	
	$domains=$sock->fetch_parsed_body();
	
	echo str_replace('_', '.', $domain).'<br>';
	
	foreach($domains as $domain=>$data) {
		//get domain pointers for domain
		$sock->query(
			'/CMD_API_DOMAIN_POINTER',
			array(
				'domain'=>str_replace('_', '.', $domain)
			)
		);
		
		$domain_pointers=$sock->fetch_parsed_body();
	}
}
?>

Authentication is done at the beginning of the script, but this is the admin login. Where (and how) should I put the admin|user part? I have tried putting the following just after the users foreach without result:

PHP:
$sock=new HTTPSocket;
$sock->connect('ssl://fqdn', 2222);
$sock->set_login('admin|user', 'pass');
 
Figured it out!

PHP:
include_once 'httpsocket.php';

$sock=new HTTPSocket;
$sock->connect('ssl://fqdn', 2222);
$sock->set_login('admin', 'pass');

//list users
$sock->query('/CMD_API_SHOW_USERS');
$users=$sock->fetch_parsed_body();

foreach($users['list'] as $user) {
    //get domains for user
    $sock->query(
        '/CMD_API_SHOW_USER_DOMAINS',
        array(
            'user'=>$user
        )
    );
   
    $domains=$sock->fetch_parsed_body();
   
    echo str_replace('_', '.', $domain).'<br>';
   
    //print_r($domains);
   
    $sock2=new HTTPSocket;
    $sock2->connect('ssl://fqdn', 2222);
    $sock2->set_login('admin|'.$user, 'pass');
   
    foreach($domains as $domain=>$data) {
        //get domain pointers for domain
        $sock2->query(
            '/CMD_API_DOMAIN_POINTER',
            array(
                'domain'=>str_replace('_', '.', $domain)
            )
        );
       
        $domain_pointers=$sock2->fetch_parsed_body();
       
        print_r($domain_pointers);
    }
}

Hopes this helps someone in the future.
 
Last edited:
Back
Top