SOAP (NuSOAP class)

Examples of accessing the Yandex.Direct API using PHP and the NuSOAP set of classes.

Getting information about the client

This example demonstrates calling the GetClientInfo (Live) method.

<?php
require_once('NuSOAP-Lib/nusoap.php');

$wsdlurl = 'https://api.direct.yandex.ru/live/v4/wsdl/';
$token = 'xxxxxx899f484ce7b0dc709fcbb36aed';
$locale = 'ru';

// Initializing the NuSOAP client
$client = new nusoap_client($wsdlurl, 'wsdl');

# Parameters for the NuSOAP client
$client->authtype = 'basic';
$client->decode_utf8 = 0;
$client->soap_defencoding = 'UTF-8';

// Forming the SOAP request headers
$client->setHeaders("<token>
$token</token><locale>$locale</locale>");

// Executing the request to the Yandex.Direct API server
$result = $client->call('GetClientInfo', array());

// Printing the request and response
echo "Request:<pre>".htmlspecialchars($client->request, ENT_QUOTES)."</pre>";
echo "Response:<pre>".htmlspecialchars($client->response, ENT_QUOTES)."</pre>";

/*
// Printing debug info 
echo '<hr><pre>'.htmlspecialchars($client->debug_str, ENT_QUOTES).'</pre>';
*/
?>

Creating a campaign

This example demonstrates calling the CreateOrUpdateCampaign (Live) method.

<?php
require_once('NuSOAP-Lib/nusoap.php');

$wsdlurl = 'https://api.direct.yandex.ru/live/v4/wsdl/';
$token = 'xxxxxx899f484ce7b0dc709fcbb36aed';
$locale = 'ru';
$login = 'campaign-owner-yandex-login';

// Initializing the NuSOAP client
$client = new nusoap_client($wsdlurl, 'wsdl');

# Parameters for the NuSOAP cilent
$client->authtype = 'basic';
$client->decode_utf8 = 0;
$client->soap_defencoding = 'UTF-8';

// Forming the SOAP request headers
$client->setHeaders("<token>$token</token><locale>$locale</locale>");


// Request input
$params = array(
    'Login' => $login,
    'CampaignID' => 0,
    'Name' => 'New Campaign',
    'FIO' => 'Ivan Ivanov',
    'Strategy' => array(
        'StrategyName' => 'HighestPosition'
    ),
    'EmailNotification' => array(
        'MoneyWarningValue' => 20,
        'WarnPlaceInterval' => 60,
        'Email' => 'agrom@yandex.ru'
    )
);

// Executing the request to the Yandex.Direct API server
$result = $client->call('CreateOrUpdateCampaign', array("params" => $params));

// Printing the request and response
echo "Request:<pre>
".htmlspecialchars($client->request, ENT_QUOTES)."</pre>
";
echo "Response:<pre>
".htmlspecialchars($client->response, ENT_QUOTES)."</pre>
";

/*
// Printing debug info 
echo '<hr><pre>
'.htmlspecialchars($client->debug_str, ENT_QUOTES).'</pre>';
*/
?>