SOAP (SOAPClient class)

Accessing the Yandex Direct API using PHP and the SOAPClient class.

Getting information about the client

This example demonstrates calling the GetClientInfo (Live) method.

<?php
ini_set("soap.wsdl_cache_enabled", "0");

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

// Initializing the SOAP client
$client = new SoapClient($wsdlurl,
    array(
        'trace'=> true,
        'exceptions' => false,
        'encoding' => 'UTF-8'
    )
);
 
// Forming the SOAP request headers
$client->__setSoapHeaders(
   array(
      new SoapHeader('API', 'token', $token, false),
      new SoapHeader('API', 'locale', $locale, false)
   )
);

// Executing the request to the Yandex Direct API server
$result = $client->GetClientInfo();

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

/*
// Printing debug info if an error occurred
if (is_soap_fault($result)) { echo("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring}, detail: {$result->detail})"); }
*/
?>

Creating a campaign

This example demonstrates calling the CreateOrUpdateCampaign (Live) method.

<?php
ini_set("soap.wsdl_cache_enabled", "0");

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

// Initializing the SOAP client
$client = new SoapClient($wsdlurl,
    array(
        'trace'=> true,
        'exceptions' => false,
        'encoding' => 'UTF-8'
    )
);
 
// Forming the SOAP request headeres
$client->__setSoapHeaders(
   array(
      new SoapHeader('API', 'token', $token, false),
      new SoapHeader('API', 'locale', $locale, false)
   )
);

// 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->CreateOrUpdateCampaign($params);

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

/*
// Printing debug info if an error occurred
if (is_soap_fault($result)) { echo("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring}, detail: {$result->detail})"); }
*/
?>