SOAP connection login using API

They have: 426 posts

Joined: Feb 2005

I have been given some access to a API service from an ad server provider that we are using and they have told me I need to login using SOAP.

I have not done this before and have been doing some reading online but cant really grasp this. Their ad server is built on asp.NET does this mean I cannot use PHP to connect to the service and use their API functions?

If someone could explain to me simply how this works I would appreciate it.

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

Simple Object Access Protocol is a cross-language method of exchanging data. I used it quite a bit when I was working with weather data from the NWS.

PHP has a native library that you can use, and there is another method I've used called nuSOAP.

Basically you form an XML request and send it to the SOAP server, and they send you an XML response. The SOAP protocol defines how the XML is formed in the request and response. It's all over HTTP/HTTPS.

They have: 426 posts

Joined: Feb 2005

I am still having issues trying to logon to the service: See the code I have already and it is not authenticating:

$username = 'username';
$password = 'password';
$client_email = '';
$useragent = 'user agenct';
$developer_token = '';
$application_token = '';

$namespace = 'domain url';

// setup a SOAP client, and assign the authentication headers to $client
$client = new SOAPClient("service URL',array('trace' => true));
$user = new SOAPHeader($namespace, 'login', $username);
$password = new SOAPHeader($namespace, 'password', $password);
//$useragent = new SOAPHeader($namespace, 'useragent', $useragent);
//$token = new SOAPHeader($namespace, 'developerToken', $developer_token);
//$client_email = new SOAPHeader($namespace, 'clientEmail', $client_email);
$headers = array($user, $password);
$client->__setSOAPHeaders($headers);

// setup parameters to pass
//$params->advertiserID = 65598;

try {
// make the call to the API
$variations = $client->getCampaigns(65598);
} catch (SOAPFault $exception) {
var_dump($client->__getLastRequest());
var_dump($client->__getLastRequestHeaders());
var_dump($exception);
exit;
}

// again, normally we'd do something useful here
echo '

';
print_r($variations);
echo '

';

They have: 121 posts

Joined: Dec 2008

What do you mean 'is not authenticating'? What responses / error messages are you receiving?

Cheers,
Shaggy.

They have: 426 posts

Joined: Feb 2005

Hi Shaggy,

This is my error now:

Fatal error: Uncaught SoapFault exception: [Client] SOAP-ERROR: Encoding: object hasn't 'AdvertiserID' property in 'path to page':15 Stack trace: #0 [internal function]: SoapClient->__call('GetCampaigns', Array) #1 /'path to page' (15): SoapClient->GetCampaigns(Array) #2 {main} thrown in 'path to page' on line 15

and this is now my code:

$login = 'username';
$password = 'password';

$client = new SoapClient("wsdl service", array('login'=>$login,'password'=>$password));

$params = array('655289');

$result = $client->GetCampaigns($params);

print_r($result);

Still no luck

They have: 121 posts

Joined: Dec 2008

That's a run time error, not an authentication error. The code believes you're missing a property: 'AdvertiserID'. I don't see you setting that property anywhere, unless this is it:

$params = array('655289');
$result = $client->GetCampaigns($params);

I have no idea what the API is like, but maybe it is expecting a hash instead?:

$result = $client->GetCampaigns(array('AdvertiserID'=>'655289'));

Cheers,
Shaggy

They have: 426 posts

Joined: Feb 2005

HI Shaggy, thanks for the reply.

Yes, you were correct in thinking advertiserID was that parameter I changed as you mention with no luck.
I think I am also having issues with Authentication now as it states in the error below:

Fatal error: Uncaught SoapFault exception: [soap:Client] System.Web.Services.Protocols.SoapException: No credentials specified à sas.api.DataProviderFactory.getDataProvider(AuthHeader credentials) dans c:\smart_ws_test\v21\App_Code\Sas\api.cs:ligne 75 à Service.GetCampaigns(Int32 AdvertiserID) dans c:\smart_ws_test\v21\App_Code\Service.cs:ligne 248 in 'path to page:39 Stack trace: #0 [internal function]: SoapClient->__call('GetCampaigns', Array) #1 'path to page(39): SoapClient->GetCampaigns(Array) #2 {main} thrown in'path to page' on line 39

I have tried creating SOAP headers for credentials with no luck:

$headerbody = array('UserName'=>$login,'Password'=>$password);//Create Soap Header.
$header = new SOAPHeader($ns, 'AuthHeader', $headerbody);
$client = new SoapClient($ns.'/v21/service.asmx?wsdl');
//set the Headers of Soap Client.
$client->__setSoapHeaders($header);
$result = $client->GetCampaigns(array('AdvertiserID'=>'655289'));
echo var_dump($result);

They have: 121 posts

Joined: Dec 2008

This is another client exception - before the request is even sent off to to the service.

The getDataProvider() method is expecting an AuthHeader object - whether that is constructed by the client code by you passing connection information, or needed to be constructed and passed by you is unclear. Hopefully the documentation helps a bit more with this?

Cheers,
Shaggy.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.