Jump to content

How to access the return array of API:Get Clients Products


nuwaninfo

Recommended Posts

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 by nuwaninfo
Forget to add some thing
Link to comment
Share on other sites

  • 2 weeks later...

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 by acsnorth
Link to comment
Share on other sites

  • 1 month later...

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']})");

}

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

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