MickeP Posted November 6, 2009 Share Posted November 6, 2009 I'm trying to use the API in, during my evaluation period of WHMCS to see what that part is capable of. When copying the API Example code, modified it a but to use another function, then I get this error message: "The following error occured: Authentication Failed". However, I've verified that I can log in if I copy & paste from sourcecode to whmch admin login, and it's the main admin user account with full access I'm trying to use. I've also tried to create a new System Service Account admin-user with full rights - that also works to log in with manually (even if I copy & paste to be sure I'm not spelling wrong) but the API gives authentication error... This is my code (but here I've replaced username/password as well as URL): Hope anyone can point me in the right directon... <? $url = "http://UrlToMyWHMCSroot/includes/api.php"; # URL to WHMCS API file $username = "admin"; # Admin username goes here $password = "demo"; # Admin password goes here $postfields["action"] = "addclient"; $postfields["firstname"] = "MyFirstName"; $postfields["lastname"] = "MyLastName"; $postfields["companyname"] = "My Company"; $postfields["email"] = "MyEmail@hotmail.com"; $postfields["address1"] = "MyAddress"; $postfields["city"] = "MyCity"; $postfields["state"] = "MyState"; $postfields["postcode"] = "MyPostcode"; $postfields["country"] = "SE"; $postfields["phonenumber"] = "012-3456789"; $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...
WHMCS Support Manager WHMCS John Posted November 6, 2009 WHMCS Support Manager Share Posted November 6, 2009 Have you added your IP to the API IP Access Restriction in Setup > General Settings > Security tab? 0 Quote Link to comment Share on other sites More sharing options...
MickeP Posted November 6, 2009 Author Share Posted November 6, 2009 Have you added your IP to the API IP Access Restriction in Setup > General Settings > Security tab? Yes. At first I had the URL a bit wrong (the api example contained the /admin subfolder but the include was found in the whmcs root folder, not the admin subfolder. When I changed that I got the IP restriction error. I quickly found help for that and added it as you describe - and after that I get the authentication error instead... So in conclusin: The URL is correct. The IP address is allowed. The username/password is valid by manual login, but not by API authentication.... humm... 0 Quote Link to comment Share on other sites More sharing options...
MickeP Posted November 6, 2009 Author Share Posted November 6, 2009 Ahhh... Found the typo. I used the API Example but replaced the $postfields[""] tags with the ones from the addclient function instead. However, the two first ones from the example should ofcourse remain untouched to hash the password: $postfields["username"] = $username; $postfields["password"] = md5($password); That's why it became failure of authentication and when I added these two babies again it worked like a charm! Thank you for your attention, and sorry for my stupidity... 0 Quote Link to comment Share on other sites More sharing options...
Onionman Posted November 6, 2009 Share Posted November 6, 2009 I have the exact same problem, IP added, user has API access but I get result=error;message=Authentication Failed IP added to allow list 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.