Jump to content

API Problem


Fabio92

Recommended Posts

Hi,

this is my first post. But i really can't manage to solve this problem. The api system has always worked well. But yesterday stopped working.

I'm using the default script:

<?php

$url = "http://www.domain.com/includes/api.php"; # URL to WHMCS API file

$username = "xxxxx"; # Admin username goes here

$password = "xxxxx"; # Admin password goes here

 

$postfields = array();

$postfields["username"] = $username;

$postfields["password"] = md5($password);

$postfields["action"] = "addinvoicepayment"; #action performed by the [[API:Functions]]

$postfields["invoiceid"] = "1";

$postfields["transid"] = "TEST";

$postfields["gateway"] = "mailin";

 

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_POST, true);

//curl_setopt($ch, CURLOPT_TIMEOUT, 100);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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") {

# Result was OK!

} else {

# An error occured

echo "The following error occured: ".$results["message"];

}

 

?>

The problem is that the api gives no answer. I get this notices:

 

Notice: Undefined offset: 1 in /home/admin/domains/domain.com/public_html/api_test.php on line 29

 

Notice: Undefined index: result in /home/admin/domains/domain.com/public_html/api_test.php on line 32

 

Notice: Undefined index: message in /home/admin/domains/domain.com/public_html/api_test.php on line 36

 

And only "The following error occured:" as result. Nothing else.

What do you think can happened? I have beed struggling for hours with no result....

Thank you so much.

Link to comment
Share on other sites

Try adding this line:

 

$info = curl_getinfo();

 

in between the lines that read:

 

$data = curl_exec($ch);

curl_close($ch);

 

So it looks like:

$data = curl_exec($ch);

$info = curl_getinfo();

curl_close($ch);

 

Then after the 'error occurred' output put this line in:

echo '<pre>'.print_r($info,1);

 

and see if you get an http response code. If you are getting a code of '0' then your firewall may be blocking your curl script and you need to whitelist your own IP address. Other codes would be helpful too... 403, 404 etc and should point you in the right direction.

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