3

I am trying out GetClient Password on External API

<?php 
$url = "http://localhost:81/whmcs/includes/api.php"; # URL to WHMCS API file goes here
$username = "admin"; # Admin username goes here
$password = "pass"; # Admin password goes here

$postfields["username"] = $username;
$postfields["password"] = md5($password);
$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") {
  echo "Success<br />
<br />
";
# Result was OK!
} else {
# An error occured
echo "The following error occured: ".$results["message"];
}
?>

Getting an error

result=error;message=Invalid IP ...

I already added the IP in General Setting -> Security Tab.

Note: I am trying this on localhost (xampp)

What am I missing here?

Phonolog
  • 6,321
  • 3
  • 36
  • 64
Vivek
  • 39
  • 1
  • 2

3 Answers3

4

This error means the API Access Key has not been added successfully to the configuration.php file. Please refer to step 7 above. The $api_access_key line should go before the closing ?> tag.

Source

You can also whitelist your IP by following

Setup>General>Security>API IP Access Restriction

Xaurav
  • 41
  • 2
0

if you have a account on whmcs, you will have to white-list the IP Address from where you want to access the api. it's a kind of security measure used by the whmcs team so as not to allow an unauthorized user use one's api. i hope this is helpful. Thanks

codedgift
  • 69
  • 7
0

Alternatively an access key can be configured to allow IP restrictions to be bypassed.

It works by defining a secret key/passphrase in the WHMCS configuration.php file which is then passed into all API calls. To configure it, add a line as follows to your configuration.php file in the root WHMCS directory.

$api_access_key = 'secret_key_passphrase_goes_here';

Following the introduction of an API Access Key, you can then include it in your API requests as follows:

?action=xxxx&username=xxx&password=xxx&accesskey=secret_key_passphrase_goes_here

More Infos: https://developers.whmcs.com/api/access-control/

NeT32
  • 13
  • 2