PHP code example of nk2ge5k / yandex-direct-api

1. Go to this page and download the library: Download nk2ge5k/yandex-direct-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nk2ge5k / yandex-direct-api example snippets


use directapi/DirectApiService;
use directapi/services/campaigns/criterias/CampaignsSelectionCriteria;
use directapi/services/campaigns/enum/CampaignStateEnum;
use directapi/services/campaigns/enum/CampaignFieldEnum;

$token = YOUR_TOKEN;
$login = CLIENT_LOGIN;

$client = new DirectApiService($token, $login);

$campaigns = $client
    ->getCampaignsService()
    ->get(
        new CampaignsSelectionCriteria(
            [   
                'States' => [
                    CampaignStateEnum::ON
                ]   
            ]   
        ),  
        CampaignFieldEnum::getValues()
    );  

foreach ( $campaigns as $campaign ) { 
    // do something
}