Ankit Saraogi
Ankit Saraogi

Reputation: 57

API2_query CPANEL Email listing output format - xmlapi

I used the following code PHP Code:

include '../xmlapi.php'; 

$ip = 'ip'; 
$root_pass = 'pwd'; 

$account = "acc"; 

$xmlapi = new xmlapi($ip); 
$xmlapi->password_auth($account,$root_pass); 
$xmlapi->set_output("json"); 
$xmlapi->set_port(2082); 
$xmlapi->set_debug(1); 
$output = $xmlapi->api2_query($account, "Email", "listpopswithdisk" ); 
print $output;  

The output was in such a format {"cpanelresult":{"apiversion":2,"preevent":{"result":1},"data":[{"mtime":1411037171,"diskquota":"unlimited","_diskused":"54

I want the output to be in a table. Can anyone suggest how can I do so

Upvotes: 0

Views: 908

Answers (1)

OXO Solutions
OXO Solutions

Reputation: 26

There are two ways of doing this

First decode jason to Array

include '../xmlapi.php'; 

$ip = 'ip'; 
$root_pass = 'pwd'; 

$account = "acc"; 

$xmlapi = new xmlapi($ip); 
$xmlapi->password_auth($account,$root_pass); 
$xmlapi->set_output("json"); 
$xmlapi->set_port(2082); 
$xmlapi->set_debug(1); 
$output = $xmlapi->api2_query($account, "Email", "listpopswithdisk" ); 
$output = json_decode($output)
print_r($output);  

Second is getting output in Array instead of jason

include '../xmlapi.php'; 

$ip = 'ip'; 
$root_pass = 'pwd'; 

$account = "acc"; 

$xmlapi = new xmlapi($ip); 
$xmlapi->password_auth($account,$root_pass); 
$xmlapi->set_output("array"); 
$xmlapi->set_port(2082); 
$xmlapi->set_debug(1); 
$output = $xmlapi->api2_query($account, "Email", "listpopswithdisk" ); 
print $output;  

Now you can print table from this array using foreach loop

echo "<table>";
foreach ($output as $key => $value){ 
      echo '<tr>';
      echo '<td>' . $key . '</td>';
      echo '<td>' . $value . '</td>';
      echo '</tr>';
 }
echo "</table>";

Upvotes: 1

Related Questions