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);
?>
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:
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With