<topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="php-sample1" xml:lang="en" xsi:noNamespaceSchemaLocation="urn:yandex:names:tc:dita:xsd:yandexTopic.xsd:1.3"SOAP (NuSOAP class)
Examples of accessing the Yandex Direct API using PHP and the NuSOAP set of classes.
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>';
*/
?>
Was the article helpful?
Previous