nuwaninfo Posted March 16, 2009 Share Posted March 16, 2009 (edited) Hi, I am using getclientsproducts to get the product details of a user. The user has 2 products. So it returns an array with that details of that 2 products. How can i access these details using PHP. I tried to use PHP DOM XML, but it reades only XML data. $url = "url"; # URL to WHMCS API file $whmcsadminusername= "username"; # Admin username goes here $whmcsadminpassword= "password"; # Admin password goes here $postfields["username"] = $whmcsadminusername; $postfields["password"] = md5($whmcsadminpassword); $postfields["action"] = "getclientsproducts"; $postfields["clientid"] = "290"; $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, $postfields); $data = curl_exec($ch); curl_close($ch); /* $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); $data = curl_exec($ch); curl_close($ch);*/ $data = explode(";",$data); foreach ($data AS $temp) { $temp = explode("=",$temp); $results[$temp[0]] = $temp[1]; } //print_r($data); echo '<pre>' . print_r($results, true) . '</pre><br /><br />'; And here is the link to the site. http://www.superquicksite.com/test_api.php I would be much appriciate your help. Thank you. Edited March 16, 2009 by nuwaninfo Forget to add some thing 0 Quote Link to comment Share on other sites More sharing options...
acsnorth Posted March 30, 2009 Share Posted March 30, 2009 (edited) The first problem you've got is that you're treating the result as though it were an array. The API is returning XML with this function - not an array as with some of the other functions. Don't bother exploding the resulting $data - just get PHP to parse the XML for you ... $reader = new XMLReader(); $reader->XML($data); while ($reader->read()){ echo $reader->name; if ($reader->hasValue) { echo ": " . $reader->value; } } $reader->close(); There is a good article here which talks about how to use the XML parser. Edited March 30, 2009 by acsnorth 0 Quote Link to comment Share on other sites More sharing options...
tomdchi Posted May 7, 2009 Share Posted May 7, 2009 AFAIK it can be put into an array. I have used the api with the following to put the response into an array: $url = "https://whmcsinstall.com/includes/api.php"; $username = $adminusername; $password = $adminpassword; $postfields["username"] = $username; $postfields["password"] = $password; $postfields["action"] = "getclientsdata"; $postfields["clientid"] = $clientid; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 100); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); $data = curl_exec($ch); curl_close($ch); $data = explode(";", $data); foreach ($data as $temp) { $temp = explode("=", $temp); $results[$temp[0]] = $temp[1]; } if ($results["result"] == "success") { $firstname = $results["firstname"]; $lastname = $results["lastname"]; $companyname = $results["companyname"]; $email = $results["email"]; $address1 = $results["address1"]; $address2 = $results["address2"]; $city = $results["city"]; $state = $results["state"]; $postcode = $results["postcode"]; $phonenumber = $results["phonenumber"]; } else { die("An error occured. Please contact support. ({$results['message']})"); } 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.