Jump to content

NUSOAP API not show results


unplugged_web

Recommended Posts

I'm trying to use a SOAP API with nusoap but am having some real problems with it. I've never used SOAP before (nor have I used NUSOAP either) and would be grateful for any help please.
This is the page I'm using to help me: http://api.dotmailer.com/v2/api.svc#op.ApiService.GetAddressBooks and this is what I'm using this to get the results:
<?php    # initialise    $username='username@apiconnector.com';    $password='password';    $error_message1="Something went wrong with client ";    $error_message2="Something went wrong with proxy ";    $error_message3="Something went wrong with result 1st ";    $error_message4="Something went wrong with result 2nd ";    $error_message5="Something went wrong with result 3rd ";    $wsdlPath = "https://apiconnector.com/v2/api.svc?wsdl";    # perform lookup      require $INSTALL['include']."/nusoap/lib/nusoap.php";      $client=new soapclient( $wsdlPath,'wsdl' );      $err=$client->getError();      if( $err ) { echo $error_message1; exit( $err ); }            # create a proxy client.      $proxy=$client->getproxy();      $err=$proxy->getError();      if( $err ) { echo $error_message2; exit( $err ); }            # call the SOAP method for GetAddressBooks.      $result=$proxy->GetAddressBooks( $username,$password );      if( $proxy->fault ) {        echo $error_message3;      } else {        $err=$proxy->getError();        if( $err ) {          echo $error_message4; exit( $err );        } else {          if( $result['error_code']!='0' ){            echo $error_message5; exit( $err );          }          GetAddressBooksResult( $result );        }      } ?>
That just outputs this Something went wrong with result 2nd wsdl error: phpType is struct, but value is not an array: see debug output for details.
From the output I can see that the problem is here if( $err ) {

 

echo $error_message4; exit( $err ); but I don't know how to fix that.
I've also checked the debug log and says this:
PHP Warning: Attempt to modify property of non-object in /ha/ha0/www/include/lib/nusoap.php on line 4694
Line 4694 is:
$this->schemas[$ns]->imports[$ns2][$ii]['loaded'] = true;
Edited by unplugged_web
Link to comment
Share on other sites

Is there any debug output that it is showing?It looks like the documentation for Nusoap is included in the download package. I would check the documentation to look for properties you can use for debugging. Post #4 on this page lists a few of them:http://community.sitepoint.com/t/consuming-web-service-from-php-using-nusoap/4385/3

Link to comment
Share on other sites

Is there any debug output that it is showing?It looks like the documentation for Nusoap is included in the download package. I would check the documentation to look for properties you can use for debugging. Post #4 on this page lists a few of them:http://community.sitepoint.com/t/consuming-web-service-from-php-using-nusoap/4385/3

 

There's around a 1mb file that I don't understand but at the bottom it says:

 

2015-03-26 17:37:23.176334 soapclient: checkWSDL

2015-03-26 17:37:23.176367 wsdl: getOperations for port '' bindingType http://schemas.xmlsoap.org/wsdl/soap/2015-03-26 17:37:23.176387 wsdl: getOperations checking port Secure_ApiService bindingType http://schemas.xmlsoap.org/wsdl/soap/2015-03-26 17:37:23.176404 wsdl: getOperations found port Secure_ApiService bindingType http://schemas.xmlsoap.org/wsdl/soap/2015-03-26 17:37:23.176478 soapclient: got 109 operations from wsdl https://apiconnector.com/v2/api.svc?wsdl for binding type soap Error Fault

 

Edited by unplugged_web
Link to comment
Share on other sites

Those look like regular status messages, "Error Fault" isn't all that helpful in finding the actual problem. I would check the various properties available on the soap object to see if there is more information there. You could use print_r or var_dump to dump the entire thing but I bet that's going to be a pretty massive pile of output if it inherits other classes.

Link to comment
Share on other sites

I'm sorry I don't really understand what you mean. If I use var_dump on $result it outputs bool(false)
while if I get a dump of $client then it looks like it outputs everything (I think it output everything from this page: https://apiconnector.com/v2/api.svc?wsdl). Although the first part of it is this:
object(soapclient)#1 (50) { ["username"]=> string(0) "" ["password"]=> string(0) "" ["authtype"]=> string(0) "" ["certRequest"]=> array(0) { } ["requestHeaders"]=> bool(false) ["responseHeaders"]=> string(0) "" ["responseHeader"]=> NULL ["document"]=> string(0) "" ["endpoint"]=> string(40) "https://apiconnector.com/v2/api.svc?wsdl" ["forceEndpoint"]=> string(0) "" ["proxyhost"]=> bool(false) ["proxyport"]=> bool(false) ["proxyusername"]=> bool(false) ["proxypassword"]=> bool(false) ["portName"]=> string(0) "" ["xml_encoding"]=> string(0) "" ["http_encoding"]=> bool(false) ["timeout"]=> int(0) ["response_timeout"]=> int(30) ["endpointType"]=> string(4) "wsdl" ["persistentConnection"]=> &bool(false) ["defaultRpcParams"]=> bool(false) ["request"]=> string(0) "" ["response"]=> string(0) "" ["responseData"]=> string(0) "" ["cookies"]=> array(0) { } ["decode_utf8"]=> bool(true) ["operations"]=> array(109) {

 

I'm not sure what to look for although I did try removing the values from the username and password fields and still got the same results. My thinking is that the username and password aren't being sent in this line - $result=$proxy->GetAddressBooks( $username,$password );

I don't know how to correct that though :(

Edited by unplugged_web
Link to comment
Share on other sites

object(soapclient)#1 (50) { ["username"]=> string(0) "" ["password"]=> string(0) ""

That shows a blank username and password, and it looks like they are properties on the $client object. If those are for the connection then it would not make sense to send a username and password as parameters to the GetAddressBooks function, unless that function expects you send a username and password as parameters. Do you have documentation on the API you're trying to use?I would look into $proxy, it looks like that's what you're using to send requests.
Link to comment
Share on other sites

If I remove the var_dump and change it so that it sends the login credentials as an array ( $result=$proxy->GetAddressBooks( array("username" => "username", "password" => "password") ); ) then I get this error:

HTTP Error: no proper separation of headers and document
If I get the results of $proxy then the top part is:
object(nusoap_proxy_2105358451)#8 (52) { ["username"]=> string(0) "" ["password"]=> string(0) "" ["authtype"]=> string(0) "" ["certRequest"]=> array(0) { } ["requestHeaders"]=> bool(false) ["responseHeaders"]=> string(0) "" ["responseHeader"]=> NULL ["document"]=> string(0) "" ["endpoint"]=> string(35) "https://apiconnector.com/v2/Api.svc" ["forceEndpoint"]=> string(0) "" ["proxyhost"]=> bool(false) ["proxyport"]=> bool(false) ["proxyusername"]=> bool(false) ["proxypassword"]=> bool(false) ["portName"]=> string(0) "" ["xml_encoding"]=> string(0) "" ["http_encoding"]=> bool(false) ["timeout"]=> int(0) ["response_timeout"]=> int(30) ["endpointType"]=> string(4) "wsdl" ["persistentConnection"]=> &bool(false) ["defaultRpcParams"]=> bool(false) ["request"]=> string(671) "POST /v2/Api.svc HTTP/1.0 Host: apiconnector.com User-Agent: NuSOAP/0.9.5 (1.123) Content-Type: text/xml; charset=ISO-8859-1 SOAPAction: "http://apiconnector.com/v2/ApiService/GetAddressBooks"

 

 

Unfortunately the only documentation I've got is this: http://api.dotmailer.com/v2/api.svc#op.ApiService.GetAddressBooks which is for SOAP rather than NUSOAP
Link to comment
Share on other sites

Sorry to ask but how would I send them properly? I spoke to dotmailer about getting contacts in a particular address book and they said that this was correct for that:

<?php$client = new SoapClient("https://apiconnector.com/v2/api.svc?wsdl");$params = array("login" => "username","password" => "password");$result =$client->GetContactsInAddressBookResponse(array('withFullData'));$array =$result->GetContactsInAddressBookResponse->GetContactsInAddressBookResult;print "<table border='2'><tr><th></th><th>addressBookId</th><th>withFullData</th></tr>";foreach($array as $k=>$v){print "<tr><td align='right'>" . ($k+1) . "</td><td>" . $v->addressBookId . "</td><td align='right'>" . $v->withFullData . "</td></tr>";}print "</table>";?>

I know it's getting different information but I've tried sending the username/password in the same way (I've tried using login as well as username) and neither of them work :(

Link to comment
Share on other sites

I'm not sure how they want you to send the username and password, but the code above doesn't use that $params array, it never sends it to the server. Check the NuSOAP documentation to see if there's a method to send a username and password. They are properties on the soap objects, so there has to be a way to set those.

Link to comment
Share on other sites

I used $client->setCredentials("user","password"); to send the login details, but I'm not getting any details at all.

I'm using AddressBooks( $result ); to display the results. The function for that is:

function AddressBooks( $result ) {  print "<table><tr><th></th><th>Id</th><th>Name</th><th>Visibility</th><th>Contacts</th></tr>";$array = $result->GetAddressBooksResponse->GetAddressBooksResult;foreach($array as $k=>$v){print "<tr><td align='right'>" . ($k+1) . "</td><td>" . $v->Id . "</td><td>" . $v->Name . "</td><td align='right'>" . $v->Visibility . "</td><td align='right'>" . $v->Contacts . "</td></tr>";}print "</table>";  }   ?>

but all I get it is the table with the headers, nothing is entered at all for the rows.

Link to comment
Share on other sites

Do another var_dump on the proxy, you should see the username and password filled out in the properties:

object(nusoap_proxy_2105358451)#8 (52) { ["username"]=> string(0) "" ["password"]=> string(0) ""...
If those properties are public then you should also be able to check $proxy->username or $proxy->password to see if they're empty.
Link to comment
Share on other sites

That's what they say in their example but after speaking to them they said that the call should only consist of a select and skip values as parameters and that this should give you an output. Now I'm really confused about how to do it. I did try using select and skip but didn't get anything so I guess I did something wrong with it :(

Link to comment
Share on other sites

I'm not sure what to tell you, I was going to say that we've had other questions about the same service here before but it looks like you were the one asking those also. It's a little strange that their example code doesn't work as given though.

Link to comment
Share on other sites

I know I posted before about this, but I didn't know that was with the old API. I spoke to dotmailer about their examples and they said that the API has moved on significantly since these articles were last updated. They also have a new version of the API and will be updating the examples soon.

They also said that the 'Get' value is the number of objects you want returned and the 'Skip' value is the number of address books you wish to skip at each time the call is run.
I tried to follow what their documentation here says. I changed the code to this:
$result=$proxy->GetAddressBooksResponse->GetAddressBooksResult(array ('count' => 30));
but that just gives me a fatal error. I'm really trying to learn this but don't understand a lot of it.
Link to comment
Share on other sites

This would probably fix the error:

$result=$proxy->GetAddressBooksResponse()->GetAddressBooksResult(array ('count' => 30));
I don't know if that will work though. It makes it kind of difficult if their API doesn't match their documentation.
Link to comment
Share on other sites

I finally got an example from dotmailer but don't know how to adapt it into NUSOAP. This is what they sent me:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://apiconnector.com/v2"><soapenv:Header/><soapenv:Body><v2:GetAddressBooks><v2:select>?</v2:select><v2:skip>?</v2:skip></v2:GetAddressBooks></soapenv:Body></soapenv:Envelope>

and said that I can use this to help: http://api.dotmailer.com/v2/api.svc#op.ApiService.GetAddressBooks

Edited by unplugged_web
Link to comment
Share on other sites

That's a SOAP envelope message, I guess they're saying that they want you send a request in that form. Your SOAP library should be able to handle creating the message and sending it though, all of that should happen behind the scenes. The point of using a SOAP library is to abstract all of the XML communication and just give you a class and object that you can use to call the various functions, that should all happen behind the scenes. The WSDL file should tell the library how to configure everything.

Link to comment
Share on other sites

I'm sorry I don't really understand. I'm just so desperate to get this sorted. I'm more than happy to pay for this to be sorted. My boss keeps asking about this and dotmailer themselves are no help at all. I'm just worried about keeping my job. Before I started the job I told them I'd had no experience of API's at all but now they want me to get this sorted.

 

As I say I'm just desperate now.

Link to comment
Share on other sites

I'm not sure how much help I can be with this, I've never used that service so I don't have any working code or anything. I would expect working code from them, even just as an example. Are you stuck with NuSOAP? Have you tried a different SOAP library?

Link to comment
Share on other sites

After continuing to search Google I came across somebody saying that I should be using 'call' with an array so I changed it to this:

$result=$proxy->call('GetAddressBooks',array('select' => 200, 'skip'=>0));

and

echo "<pre>" . print_r($result, true) . "</pre>";

That then gave me an array, part of which is this:

Array

(

[GetAddressBooksResult] => Array

(

[ApiAddressBook] => Array

(

[0] => Array

(

[id] => 872366

[Name] => Test

[Visibility] => Private

[Contacts] => 14

)

[1] => Array

(

[id] => 872442

[Name] => Employees

[Visibility] => Private

[Contacts] => 6968

)

.....

)

)

)

 

but I don't know how to get that in a format that is more readable for people

Edited by unplugged_web
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...