Jump to content

How to use API returned variables


silkhost

Recommended Posts

Hello,

 

How do I access the returned variables when making an API call. I have tried many different ways to no avail. I am editting the supportticketslist.tpl. Here is what I have so far with all the fields changed for my site. The call is supposed to return the users data which I am trying to retrieve. For example, the clients email, companyname. Any help would be great.

 

 

$url = "http://www.mydomainlocation.com/whmcs/includes/api.php";

$username = "Adminuser"; # Admin username goes here

$password = "password"; # Admin password goes here

$postfields["username"] = $username;

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

$postfields["action"] = "getclientsdata";

$postfields["email"] = "demo@whmcs.com";

Link to comment
Share on other sites

Heya silk,

 

I'm still reading in the API, ran no productive tests yet.. but accoring to their example in the manual you're missing this calls to curl:

 

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
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];
}

 

The $postfields-Array contains the APIcall, the return values will be saved to the $data Variable :)

Link to comment
Share on other sites

Seeing as you're adding code to WHMCS you should simply be querying the database, rather than using the API, which opens a second, unnecessary, connection.

 

Set either $client_email to the email address of the client, or $client_id to the client's ID number before this code:

$query = mysql_query("SELECT * FROM `tblclients` WHERE ((`email` = '" . mysql_real_escape_string($client_email) . "') || (`id` = '" . mysql_real_escape_string($client_id) . "'));");
if(mysql_num_rows($query) != 1)
{
echo "Error!";
} else {
$data = mysql_fetch_assoc($query);
echo $data['companyname'];
}

 

$data is now an array containing all the customer's details.

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