RPS Posted February 13, 2008 Share Posted February 13, 2008 For anyone who is familiar with the WHMCS api, if I put the following code into a new php file, and visit it, should it work? assume the url, username, and password are all correct <?php $url = "http://www.domain.com/whmcs/includes/api.php"; # URL to WHMCS API file goes here $username = "user"; # Admin username goes here $password = "pass"; # Admin password goes here $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]; } if ($results["result"]=="success") { # Result was OK! } else { # An error occured echo "The following error occured: ".$results["message"]; } ?> 0 Quote Link to comment Share on other sites More sharing options...
WHMCS CEO Matt Posted February 13, 2008 WHMCS CEO Share Posted February 13, 2008 No, it won't work as you haven't set any command 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted February 13, 2008 Author Share Posted February 13, 2008 Thanks Matt, so you're saying I need to do: <?php $url = "http://www.domain.com/whmcs/includes/api.php"; # URL to WHMCS API file goes here $username = "user"; # Admin username goes here $password = "pass"; # Admin password goes here $postfields["action"] = "getclientpassword"; $postfields["userid"] = "1"; $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]; } if ($results["result"]=="success") { # Result was OK! } else { # An error occured echo "The following error occured: ".$results["message"]; } ?> 0 Quote Link to comment Share on other sites More sharing options...
WHMCS CEO Matt Posted February 13, 2008 WHMCS CEO Share Posted February 13, 2008 Correct, you need to send the username and password aswell. Would probably help if you actually use the full example provided in the manual: http://v3manual.whmcs.com/?id=134 Matt 0 Quote Link to comment Share on other sites More sharing options...
RPS Posted February 13, 2008 Author Share Posted February 13, 2008 Ahhh, that was the problem. Even though the user/pass is declared, this still needs to be listed: $postfields["username"] = $username; $postfields["password"] = md5($password); Thanks Matt 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.