Jump to content

API - "Authentication Failed"


MickeP

Recommended Posts

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


?>

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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...

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