eccen Posted June 4, 2010 Share Posted June 4, 2010 I am having trouble trying to implement client add api... I keep getting "The following error occured: Authentication Failed" in return.. and yes, I added correct IP address to API IP Access Restriction under Genera Settings > Security Help please Here is my testing code: <? $url = "http://www.mydomain.com/whmcs/includes/api.php"; $username = "admin"; $password = "adminpass"; $postfields["action"] = "addclient"; $postfields["firstname"] = "Test"; $postfields["lastname"] = "User"; $postfields["companyname"] = "WHMCS"; $postfields["email"] = "demo@whmcs.com"; $postfields["address1"] = "123 Demo Street"; $postfields["city"] = "Demo"; $postfields["state"] = "Florida"; $postfields["postcode"] = "AB123"; $postfields["country"] = "US"; $postfields["phonenumber"] = "123456789"; $postfields["password2"] = "demo"; $postfields["currency"] = "1"; $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") { # 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...
eccen Posted June 4, 2010 Author Share Posted June 4, 2010 Found a solution. Change: $username = "API-username"; # Admin username goes here $password = "API-password"; # Admin password goes here To: $postfields["username"] = "API-username"; # Admin username goes here $postfields["password"] = md5("API-password"); # Admin password goes here Seems like WHMCS documentation has some false information 0 Quote Link to comment Share on other sites More sharing options...
tinderbox Posted August 27, 2010 Share Posted August 27, 2010 Took me an hour to find this. It would be awesome if WHMCS's own API docs weren't just flat out wrong. 0 Quote Link to comment Share on other sites More sharing options...
laszlof Posted August 27, 2010 Share Posted August 27, 2010 Took me an hour to find this. It would be awesome if WHMCS's own API docs weren't just flat out wrong. They aren't wrong. This is directly from the API Example page: <?php $url = "http://www.yourdomain.com/whmcs/includes/api.php"; # URL to WHMCS API file $username = "Admin"; # Admin username goes here $password = "demo"; # Admin password goes here $postfields["username"] = $username; $postfields["password"] = md5($password); $postfields["action"] = "addinvoicepayment"; #action performed by the API:Functions $postfields["invoiceid"] = "1"; $postfields["transid"] = "TEST"; $postfields["gateway"] = "mailin"; $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") { # Result was OK! } else { # An error occured echo "The following error occured: ".$results["message"]; } ?> You just left the first 2 postfields out. 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.