3

I'm trying to use the WHMCS API, for example to get client. So when I run the file PHP,it gave me this error in Json:

{"result":"error","message":"Authentication Failed"}

and when I test username and password they authenticate in the website.

Please suggest a solution.

<?php
// Création d'une ressource cURL
$ch = curl_init();
//L'URL à récupérer
curl_setopt($ch, CURLOPT_URL, 'https://example.com/includes/api.php');
//TRUE pour que PHP fasse un HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//les données à passer lors d'une opération de HTTP POST
curl_setopt($ch, CURLOPT_POSTFIELDS,
    http_build_query(
        array(
            'action' => 'GetClients',
            'username' => 'myUsername', 
            'password' => 'myPassword',                 
            'responsetype' => 'json')
    )
);

$response = curl_exec($ch);
curl_close($ch);
// Decode response
$jsonData = json_decode($response, true);
// Dump array structure for inspection
//var_dump($jsonData);

?>
Tom Udding
  • 2,264
  • 3
  • 20
  • 30
S.Snoy
  • 39
  • 8

1 Answers1

1

Your problem could have some different reasons.

It's not clear if you hash the password, you should not send password in clear text. Hash with md5() before sending.

Other things to check:

  • Make sure the user has "API Access" granted to their admin group.
  • Allow IP-address for accessing api: Setup > General Settings > Security
  • You can bypass ip-check by specifying $api_access_key with a secret value in configuration.php and send it in postfields as variable "accesskey".

Good luck!