Jump to content

message=Authentication Failed


terungwa

Recommended Posts

I have reviewed the responses in relation to this question I am asking here but, none successfully addresses this issue

 

I am using the Get Clients Details API to retrieve some data held about a client in the WHMCS System for a given ID via a hook to be called each time a client logs into the backend.

 

 

This is my code:

function hook_obtain_client_details_on_login($params) { 
	$url = "http://bemastech.com/store/includes/api.php";
	$userid = $params['userid'];
	$postfields["action"] = "getclientsdetails";
	$postfields["clientid"] = "{$userid}"; 		

	$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);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
	$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")
	{
		$_SESSION['email'] = $results["email"];
		$_SESSION['phonenumber'] = $results["phonenumber"];
		$_SESSION['userid'] = $results["userid"];
	}
	else
	{
		die("An error occured. Please contact support. ({$results['message']})");
	} 
}
add_hook("ClientLogin",1,"hook_obtain_client_details_on_login","");

 

But, on login, this error is thrown up from my script:

 

array(3) { [0]=> string(12) "result=error" [1]=> string(29) "message=Authentication Failed" [2]=> string(0) "" } 

 

My IP Address has been allowed to connect to the WHMCS API.

I am using WHMCS Version 6.1.1

 

How can I resolve this problem ? Thank you in advance.

Link to comment
Share on other sites

You are using your API function inside an action hook so there's really no need to use external API. Simply use internal API:

$command = "getclientsdetails";
$adminuser = "admin";
$values["clientid"] = "1";
$values["stats"] = true;
$values["responsetype"] = "xml";

$results = localAPI($command,$values,$adminuser);

Also notice that in your script you were using this:

$postfields["clientid"] = "{$userid}";

"{$userid}" makes no sense. Responsetype parameter (xml) was missing. Lastly you did not specify username and the MD5 password to connect to WHMCS.

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