Jump to content

Getting External API to work: Empty result


Recommended Posts

I am wrestling with the documentation trying to figure out what I need to do to make the external API work. I've created a php file and placed it in the WHMCS directory, and I think I have it set up correctly according to the documentation, but it always gives an empty response.


I am trying to do a module password change as described here.


Here is the code:


$url = "path/to/includes/api.php"; 
$username = "admin"; 
$password = "mysupersecurepassword"; 

$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "modulechangepw";
$postfields["serviceid"] = "11";
$postfields["servicepassword"] = "anewpassword";

$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);

$data = explode(";",$data);
foreach ($data AS $temp) {
  $temp = explode("=",$temp);
  $results[$temp[0]] = $temp[1];

if ($results["result"]=="success") {
   echo "OK!";
} else {
   echo $results["result"] . "The following error occured: ". $results["message"];



The output page is simply:


The following error occurred:
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.

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.

  • 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