Jump to content

SOAP API - how do I get the results?


unplugged_web
 Share

Recommended Posts

I've never worked with SOAP before so am not exactly sure how to display the results from this:

<?php$client = new SoapClient("https://api.massmailer.com/v2/address-books/{AddressBookId}/contacts?withFullData={withFullData}");$params = array("username" => "USERNAME", "password" => "PASSWORD");$result = $client->GetAddressBookContacts($params);var_dump($result);echo "done";?>

If I go to the page this is on nothing is rendered at all. Even the var_dump() is empty, but if I go to https://api.massmailer.com/v2/address-books/{AddressBookId}/contacts?withFullData={withFullData} I'm prompted to enter the API username and password then it displays everything.

Ideally I'd like to get everything from the address book.

Edited by unplugged_web
Link to comment
Share on other sites

var_dump never just displays nothing. I bet if you enable error messages on that page, you'll see a fatal error that $client does not have a method called GetAddressBookContacts. I bet the reason for that is because the URL you're sending to the SoapClient constructor is not a WSDL URL. I can't verify that, because that URL doesn't work for me.http://php.net/manual/en/soapclient.soapclient.php

Link to comment
Share on other sites

I got the url wrong sorry, it's actually https://api.dotmailer.com/v2/address-books/160189/contacts?withFullData={withFullData} - I was worried about posting anything sensitive.

The actual error I get in the logs is PHP Fatal error: Call to undefined method soapclient::GetAddressBookContacts() but GetAddressBookContacts() is the value I got from dot mailers site: https://api.dotmailer.com/v2/help/wadl#GetContactsInAddressBook

Link to comment
Share on other sites

You're linking to the REST API, not the SOAP API. The WSDL for the SOAP API is here:https://api.dotmailer.com/v2/api.svc?wsdl

 

  • I've followed this as best as I can: https://api.dotmailer.com/v2/api.svc#op.ApiService.GetContactsInAddressBook and have now changed the code to this:
  • <?php$client = new SoapClient("http://apiconnector.com/v2/ApiService/GetContactsInAddressBook");$params = array("username" => "*******", "password" => "*******", "addressBookId" => "160189");$result = $client->GetContactsInAddressBook($params);var_dump($result);echo "done";?>
  • but again that gives an error about the 'GetContactsInAddressBook'. If I replace that line with
    $result = $client;
    I get an output that doesn't give me the data I need

Link to comment
Share on other sites

You're still doing the same thing wrong. You're trying to use a REST API URL as the WSDL for the SOAP service. If you didn't understand what I just said, then you need to read more about how SOAP works. When you create a SOAP client you need to give it the URL of a WSDL file. You're not doing that. You're giving it the URL of a REST API endpoint. I even posted the URL of the SOAP WSDL in the previous post. That is what you use to configure the SOAP client, that is how the SOAP client figures out which methods and properties are available. It sounds like you're just trying various things without understanding how it works, that's why you're having problems. Stop guessing and start understanding what you're trying to use.

Link to comment
Share on other sites

  • 3 weeks later...

I've tried to read up about SOAP API's and have now changed it to this:

<?php$client = new SoapClient("https://apiconnector.com/v2/api.svc?wsdl");$params = array("username" => "username", "password" => "password");$result = $client->GetContactsInAddressBook(array('withFullData'=>5));$array = $result->GetContactsInAddressBook->GetContacts;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>";?>

but I'm still not getting anything. I've checked the error log an it says this

 

Call to undefined method soapclient::GetContactsInAddressBook()
but I don't understand as it looks like that's what it says it should be?
Link to comment
Share on other sites

If you need to authenticate with the soap service then you need to password the login and password options to the constructor when you create the new object. There are several examples of using the options here:http://php.net/manual/en/soapclient.soapclient.php

I changed that but am still getting the same PHP Fatal error: Call to undefined method soapclient::GetContactsInAddressBook() error. The code I'm using is:

<?php$client = new SoapClient("https://apiconnector.com/v2/api.svc?wsdl", array("username" => "xxxxxxxxxx", "password" => "xxxxxxxxxx", "addressBookId" => "xxxxxxxxxx"));$result = $client->GetContactsInAddressBook(array('withFullData'));$array = $result->GetContactsInAddressBook->GetContacts;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 really don't know what I'm doing wrong here as I've followed help/tutorials and read about it but it's still not working :(

Link to comment
Share on other sites

According to the PHP manual the option isn't "username", it's "login". The SoapClient class doesn't have an option called "addressBookId". This is setting up the general SOAP client, not using the specific API. You would send the address book ID with the call to the next method, not when creating the SOAP client.

Link to comment
Share on other sites

According to the PHP manual the option isn't "username", it's "login". The SoapClient class doesn't have an option called "addressBookId". This is setting up the general SOAP client, not using the specific API. You would send the address book ID with the call to the next method, not when creating the SOAP client.

 

I was following the instructions from dot mailers website: https://support.dotmailer.com/entries/20668943-Accessing-the-API-using-PHP but will try it with login rather than username and remove the addressBookId.
One question though, the error log says that the problem is on this line: $result = $client->GetContactsInAddressBook(array('withFullData')); which is after the username/login line, does that not mean that username is okay or have I misread the error?
EDIT: I tried login instead of username and that gave the same "PHP Fatal error: Call to undefined method soap client::GetContactsInAddressBook() error."
Edited by unplugged_web
Link to comment
Share on other sites

all it means is that there is something "wrong" with $client, which is the instance of SoapClient. It was not instantiated correctly which is why you get errors trying to call methods on it. Are you sure your login credentials are correct?

Link to comment
Share on other sites

I tried using their code but that gave the same error but for the ListAddressBooks method:

PHP Fatal error: Call to undefined method soapclient::ListAddressBooks()

Even if I try it with login instead of username it still fails.

I've also double checked the credentials and they correct

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
 Share

×
×
  • Create New...