Jump to content

WHMCS API Help


jubba890
Go to solution Solved by Barand,

Recommended Posts

I am using WHMCS API and It gives me an array for the first name, last name, etc for the client information

 

Here is the code I have so far

 

checkLogin.php

<?php 
 session_start(); 
 echo "ID: " . $_SESSION['clientID']; 
 $postfields = array(); 
 $postfields["action"] = "getclientsdetails"; 
 $postfields["clientid"] = $_SESSION['clientID']; 
 $postfields["stats"] = true; 
 $postfields["responsetype"] = "xml"; 
 echo "<br>"; 
 include('XMLAPI.php'); 
 ?>

XMLAPI.php

<?php 
 /* *** WHMCS XML API Sample Code *** */ 
  
 $url = "http://inzernettechnologies.com/billing/includes/api.php"; # URL to WHMCS API file 
 $username = "user"; # Admin username goes here 
 $password = "pass"; # Admin password goes here 

 $postfields["username"] = $username; 
 $postfields["password"] = md5($password); 

 $query_string = ""; 
 foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; 
  
 $ch = curl_init(); 
 curl_setopt($ch, CURLOPT_URL, $url); 
 curl_setopt($ch, CURLOPT_POST, 1); 
 curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
 curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); 
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
 $xml = curl_exec($ch); 
 if (curl_error($ch) || !$xml) $xml = '<whmcsapi><result>error</result>'. 
 '<message>Connection Error</message><curlerror>'. 
 curl_errno($ch).' - '.curl_error($ch).'</curlerror></whmcsapi>'; 
 curl_close($ch); 
  
 $arr = whmcsapi_xml_parser($xml); # Parse XML 
  
 print_r($arr); # Output XML Response as Array 
  
 /* 
 Debug Output - Uncomment if needed to troubleshoot problems 
 echo "<textarea rows=50 cols=100>Request: ".print_r($postfields,true); 
 echo "\nResponse: ".htmlentities($xml)."\n\nArray: ".print_r($arr,true); 
 echo "</textarea>"; 
 */ 
  
 function whmcsapi_xml_parser($rawxml) { 
     $xml_parser = xml_parser_create(); 
     xml_parse_into_struct($xml_parser, $rawxml, $vals, $index); 
     xml_parser_free($xml_parser); 
     $params = array(); 
     $level = array(); 
     $alreadyused = array(); 
     $x=0; 
     foreach ($vals as $xml_elem) { 
       if ($xml_elem['type'] == 'open') { 
          if (in_array($xml_elem['tag'],$alreadyused)) { 
              $x++; 
              $xml_elem['tag'] = $xml_elem['tag'].$x; 
          } 
          $level[$xml_elem['level']] = $xml_elem['tag']; 
          $alreadyused[] = $xml_elem['tag']; 
       } 
       if ($xml_elem['type'] == 'complete') { 
        $start_level = 1; 
        $php_stmt = '$params'; 
        while($start_level < $xml_elem['level']) { 
          $php_stmt .= '[$level['.$start_level.']]'; 
          $start_level++; 
        } 
        $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];'; 
        @eval($php_stmt); 
       } 
     } 
       return($params); 
 } 
  
 ?>

It outputs:

ID: 1
Array ( [WHMCSAPI] => Array ( [ACTION] => getclientsdetails [RESULT] => success [CLIENT] => Array ( [USERID] => 1 [ID] => 1 [FIRSTNAME] => Cody [LASTNAME] => Robinson [FULLNAME] => Cody Robinson [COMPANYNAME] => InZernet Technologies [EMAIL] => cody-admin@inzernettechnologies.com [ADDRESS1] => Address [ADDRESS2] => [CITY] => 11 [FULLSTATE] => Michigan [STATE] => Michigan [POSTCODE] => 11111 [COUNTRYCODE] => US [COUNTRY] => US [STATECODE] => MI [COUNTRYNAME] => United States [PHONECC] => 1 [PHONENUMBER] => 1111111111 [PHONENUMBERFORMATTED] => 11111111 [BILLINGCID] => 0 [NOTES] => [PASSWORD] => PASSWORD [TWOFAENABLED] => [CURRENCY] => 1 [DEFAULTGATEWAY] => [CCTYPE] => [CCLASTFOUR] => [SECURITYQID] => 29 [SECURITYQANS] => Rogers [GROUPID] => 0 [STATUS] => Active [CREDIT] => 0.00 [TAXEXEMPT] => [LATEFEEOVERIDE] => [OVERIDEDUENOTICES] => [SEPARATEINVOICES] => [DISABLEAUTOCC] => [EMAILOPTOUT] => 0 [OVERRIDEAUTOCLOSE] => 0 [LANGUAGE] => [LASTLOGIN] => Date: 07/10/2014 17:43
IP Address: xx.xx.xx.xx.xx
Host: xx.xx.xx.xx.xx.xx.xx [CUSTOMFIELDS1] => Other [CUSTOMFIELDS] => Array ( [ID] => 1 [VALUE] => Other ) [CURRENCY_CODE] => USD ) [STATS] => Array ( [NUMDUEINVOICES] => 0 [DUEINVOICESBALANCE] => $0.00 USD [INCOME] => $0.00 USD [INCREDIT] => [CREDITBALANCE] => $0.00 USD [NUMOVERDUEINVOICES] => 0 [OVERDUEINVOICESBALANCE] => $0.00 USD [NUMPAIDINVOICES] => 0 [PAIDINVOICESAMOUNT] => $0.00 USD [NUMUNPAIDINVOICES] => 0 [UNPAIDINVOICESAMOUNT] => $0.00 USD [NUMCANCELLEDINVOICES] => 0 [CANCELLEDINVOICESAMOUNT] => $0.00 USD [NUMREFUNDEDINVOICES] => 0 [REFUNDEDINVOICESAMOUNT] => $0.00 USD [NUMCOLLECTIONSINVOICES] => 0 [COLLECTIONSINVOICESAMOUNT] => $0.00 USD [PRODUCTSNUMACTIVEHOSTING] => 0 [PRODUCTSNUMHOSTING] => 0 [PRODUCTSNUMACTIVERESELLER] => 0 [PRODUCTSNUMRESELLER] => 0 [PRODUCTSNUMACTIVESERVERS] => 0 [PRODUCTSNUMSERVERS] => 0 [PRODUCTSNUMACTIVEOTHER] => 0 [PRODUCTSNUMOTHER] => 0 [PRODUCTSNUMACTIVE] => 0 [PRODUCTSNUMTOTAL] => 0 [NUMACTIVEDOMAINS] => 0 [NUMDOMAINS] => 0 [NUMACCEPTEDQUOTES] => 0 [NUMQUOTES] => 0 [NUMTICKETS] => 0 [NUMACTIVETICKETS] => 0 [NUMAFFILIATESIGNUPS] => 0 ) ) )

How would I get that information into a variable

I tried $params[1];

and that didn't work

I tried to remove the return($params);

and use it in CheckLogin.php and did

echo $params;

but it didn't work

Any help appreciated!!!!!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.