Jump to content
mastura

display api get data into table form

Recommended Posts

Hi.. I have been working on this for 4 days now and still not able to find a right solution.
i have the get client data using api to display it in other platform but it displays in array form. Since i am new to coding,
I need it to display in table form . How am i able to do it ?
please help me

here the code applied:

// API Connection Details
$whmcsUrl = "https://domain.com/";

// For WHMCS 7.2 and later, we recommend using an API Authentication Credential pair.
// Learn more at http://docs.whmcs.com/API_Authentication_Credentials
// Prior to WHMCS 7.2, an admin username and md5 hash of the admin password may be used.
$username = "xxxxxxxxxxxxxxxxxxxxxxx";
$password = "yyyyyyyyyyyyyyyyyyyyyyyyy";

// Set post values
$postfields = array(
    'username' => $username,
    'password' => $password,
    'action' => 'GetClients',
    'responsetype' => 'json',
);

// Call the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $whmcsUrl . 'includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
$response = curl_exec($ch);
if (curl_error($ch)) {
    die('Unable to connect: ' . curl_errno($ch) . ' - ' . curl_error($ch));
}
curl_close($ch);

// Decode response
$jsonData = json_decode($response, true);

// Dump array structure for inspection
var_dump($jsonData);?>

 

Here is the result: 
image.thumb.png.2e8964ea4f53b556f5ea8ce1a993ae20.png

 

Please help me solve this..Thank you

Share this post


Link to post
Share on other sites
<?

// API Connection Details
$whmcsUrl = "https://domain.com/";

// For WHMCS 7.2 and later, we recommend using an API Authentication Credential pair.
// Learn more at http://docs.whmcs.com/API_Authentication_Credentials
// Prior to WHMCS 7.2, an admin username and md5 hash of the admin password may be used.
$username = "xxxxxxxxxxxxxxxxxxxxxxx";
$password = "yyyyyyyyyyyyyyyyyyyyyyyyy";

// Set post values
$postfields = array(
    'username' => $username,
    'password' => $password,
    'action' => 'GetClients',
    'responsetype' => 'json',
);

// Call the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $whmcsUrl . 'includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
$response = curl_exec($ch);
if (curl_error($ch)) {
    die('Unable to connect: ' . curl_errno($ch) . ' - ' . curl_error($ch));
}
curl_close($ch);

// Decode response
$jsonData = json_decode($response, true);

// EDITED BELOW THIS LINE

$table .= <<<HTML
Showing <strong>{$jsonData['numreturned']}</strong> of <strong>{$jsonData['totalresults']}</strong> clients<hr>
<table>
	<tr>
		<th>Client Name</th>
		<th>Email</th>
		<th>Status</th>
	</tr>
HTML;

foreach ($jsonData['clients']['client'] as $v)
{
	$table .= <<<HTML
	<tr>
		<td>{$v['firstname']} {$v['firstname']} {$v['companyname']}</td>
		<td>{$v['email']}</td>
		<td>{$v['status']}</td>
	</tr>
HTML;
}
	
$table .= <<<HTML
</table>
HTML;

echo $table;

This will produce the following:

1833518820_Screenshot2019-05-0901_53_16.png.8a8df9506ebe1e013a20b163833a9023.png

Anyway this is not how you should that. I gave you just an example.

 

Share this post


Link to post
Share on other sites
55 minutes ago, Kian said:

<?

// API Connection Details
$whmcsUrl = "https://domain.com/";

// For WHMCS 7.2 and later, we recommend using an API Authentication Credential pair.
// Learn more at http://docs.whmcs.com/API_Authentication_Credentials
// Prior to WHMCS 7.2, an admin username and md5 hash of the admin password may be used.
$username = "xxxxxxxxxxxxxxxxxxxxxxx";
$password = "yyyyyyyyyyyyyyyyyyyyyyyyy";

// Set post values
$postfields = array(
    'username' => $username,
    'password' => $password,
    'action' => 'GetClients',
    'responsetype' => 'json',
);

// Call the API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $whmcsUrl . 'includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));
$response = curl_exec($ch);
if (curl_error($ch)) {
    die('Unable to connect: ' . curl_errno($ch) . ' - ' . curl_error($ch));
}
curl_close($ch);

// Decode response
$jsonData = json_decode($response, true);

// EDITED BELOW THIS LINE

$table .= <<<HTML
Showing <strong>{$jsonData['numreturned']}</strong> of <strong>{$jsonData['totalresults']}</strong> clients<hr>
<table>
	<tr>
		<th>Client Name</th>
		<th>Email</th>
		<th>Status</th>
	</tr>
HTML;

foreach ($jsonData['clients']['client'] as $v)
{
	$table .= <<<HTML
	<tr>
		<td>{$v['firstname']} {$v['firstname']} {$v['companyname']}</td>
		<td>{$v['email']}</td>
		<td>{$v['status']}</td>
	</tr>
HTML;
}
	
$table .= <<<HTML
</table>
HTML;

echo $table;

This will produce the following:

1833518820_Screenshot2019-05-0901_53_16.png.8a8df9506ebe1e013a20b163833a9023.png

Anyway this is not how you should that. I gave you just an example.

 

heyy..thank you so much ..this works wonder..

but why there is an error/notices prompted at the top of the table?
how do i assign the table variable?

Share this post


Link to post
Share on other sites
 
 
 
2
20 minutes ago, mastura said:

heyy..thank you so much ..this works wonder..

but why there is an error/notices prompted at the top of the table?
how do i assign the table variable?

 

capture.JPG

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By ModulesGarden
      1. This is the kind of news we love sharing the most! Our Domains Reseller For WHMCS module has been upgraded to the landmark 2.0 version, thus pioneering a whole new direction in which the tool will be heading from now on. 
      Starting with the spectacular framework redesign, the module embraced also a varied range of new functionalities, including:

      Possibility to set up different domain pricing rates for individual reseller groups in the module addon Dynamic statistics in admin dashboard summarizing total income plus income from specific TLDs from a chosen time period Advanced API documentation, enabling both admin providers and resellers to create custom submodules Complete overview of reseller details such as TLDs pricing, end users’ orders, or logs now conveniently stored in their own Reseller Area
      Go carefully through the full changelog and let flexibility settle in your business routine for good! AP
      Learn more about Domains Reseller For WHMCS 2.0!
       
      2. EasyDCIM - a cutting-edge tool automating daily data center operations, has recently received a solid 1.5.5 update.
      Among the new utilities administrators are now free to use are the practical tooltips with overview on users and most device types supported by the system, as well as extended features related to QR codes, allowing now to easily label the physical equipment in a server room. 
      Head right over to the official EasyDCIM Blog for extra info!
       
      3. Check out also our other recent module updates:

      EURid Registrar For WHMCS - 1.2.2 Password Manager For WHMCS - 2.2.5 - 2.2.5
      Support Tickets Allocator For WHMCS - 1.3.0



      Need Custom Software Development For Your Business?

      Get Your Free Quote Now! Specially for you we will adapt an application and its design to your own needs, create a new module or even a completely new system built from scratch!
    • By bellafronte
      Hello, community!
       
      I'm doing some experiments with the API UpdateTransaction  but it looks like it is not working with any combination of parameters.
      I used the required parameter transactionid and tried to update the fee and description, but nothing happens. The API returns success.


       
    • By WHMCS John
      An issue has been identified in the 7.4.2 release - published on 9th January, 2018 - that is causing the GetProducts API command not to return product data in the expected format.
      Data is incorrectly returned as:
      Array ( [result] => success [totalresults] => )  
    • By vinc1402
      Hello WHMCS, 
      I have a problem that is bothering me for a while now, the table or grid showing domain, service or invoice info look great on desktops but on mobile it breaks outside the site its layout and causing the max width of the design to drastically increase.
       
       
      Notice where the site has its right border, the table frame is completely outside of it. (causing the entire layout to stretch on mobile)

       
      I've noticed that it is present on almost all WHMCS systems, although if the content inside isn't that much it doesn't seem to be a problem.
      If you have any suggestions?
       
      Kind regards,
      Vincent
       
    • By wellconnit
      Hi All,
       
      I've written some PHP to extract client files from the WHMCS database because it's not a native API call.
      Just opened the thread to share it with anyone who may want to use it.
      I'm working on another to update the Last Login details also.
      Create the SQL Connection then
      Get the Files List - Pass $userID as the clientID - While loop ensures all records are put into the arrary
      function getfiles($userID)
      {
      $conn = new mysqli('DBAddress', 'DBUser', 'DBPW', 'DBName')
      $result = $conn->query("SELECT * FROM `tblclientsfiles` WHERE userid = $userID");
          $rows = array();
          while($row = $result->fetch_assoc()) {
              $rows[] = $row;
          }
       return $rows;
      }
      $filesData = getfiles($userID);
       for ($counter = 0; $counter < count($rows); $counter++)
              { 
                  $split = explode("_", $filesData[$counter]['filename']);
              echo "<tr><td>" . $split['1'] . "</td><td><a href='WHMCSWebsite/attachments" .$filesData[$counter]['filename']. "'>Download</a></td></tr>";
              }
      That should be enough for people to be able to extract the files list and display it through the API.
  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated