<?php
use \common\components\UnisenderAPI;
use \yii\helpers\Json;

$email = 'bystrov@kupitsite.ru';

$sender = new UnisenderAPI();
// Create the send list
$newList = $sender->createList();
$newListObject=Json::decode($newList);
if (array_key_exists('result', $newListObject) && array_key_exists('id', $newListObject['result'])) {
    $newListId=$newListObject['result']['id'];
    // Subscribe user to new List
    $subscribe = $sender->subscribe(['list_ids' => $newListId, 'fields[email]' => $email, 'double_optin' => 1]);
    // Create new message
    $newMessage=$sender->createEmailMessage('bystrov', $email, 'Testing Subject', 'Testing Body <br><a href="http://www.google.com/">Testing link</a><br><a href="{{_UnsubscribeUrl}}">Отписаться</a>', $newListId);
    // Decode result
    $newMessageObject=Json::decode($newMessage);
    if (array_key_exists('result', $newMessageObject) && array_key_exists('message_id', $newMessageObject['result'])) {
        // Get the message ID
        $newMessageId=$newMessageObject['result']['message_id'];
        // Create new campaign
        $newCampaign = $sender->createCampaign($newMessageId);
        // Parse the result
        $newCampaignObject = Json::decode($newCampaign);
        if (array_key_exists('result', $newCampaignObject) && array_key_exists('campaign_id', $newCampaignObject['result'])) {
            $newCampaignId = $newCampaignObject['result']['campaign_id'];
        }
    }
}

echo 'Рассылка: '.((isset($newCampaignId)) ? $newCampaignId : 'Not found');
echo '<br>';
echo 'Список: '.((isset($newListId)) ? $newListId : 'Not found');
echo '<br>';
echo 'Сообщение: '.((isset($newMessageId)) ? $newMessageId : 'Not found');