PHP code example of romanpitak / dotmailer-api-v2-client

1. Go to this page and download the library: Download romanpitak/dotmailer-api-v2-client 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/ */

    

romanpitak / dotmailer-api-v2-client example snippets



dentials = array(
    Container::USERNAME => '[email protected]',
    Container::PASSWORD => 'YYYYYYYYYYYYYYYYYYYYYYYYYYY'
);

$resources = Container::newResources($credentials);

echo $resources->GetAccountInfo();


dentials = array(
    'master' => array(
        Container::USERNAME => '[email protected]',
        Container::PASSWORD => 'YYYYYYYYYYYYYYYYYYYYYYYYYYY'
    ),
    'group1' => array(
        'g1-account1' => array(
            Container::USERNAME => '[email protected]',
            Container::PASSWORD => 'YYYYYYYYYYYYYYYYYYYYYYYYYYY'
        ),
        'g1-account2' => array(
            Container::USERNAME => '[email protected]',
            Container::PASSWORD => 'YYYYYYYYYYYYYYYYYYYYYYYYYYY'
        )
    )
);

$container = Container::newContainer($credentials);

echo $container->getResources('master')->GetSegments();

$dataField = new ApiDataField();
$dataField->name = 'MY_DATA_FIELD';
$dataField->type = ApiDataTypes::STRING;
$dataField->visibility = ApiDataFieldVisibility::HIDDEN;

foreach ($container->group1 as $resources) {
    try {
        $resources->PostDataFields($dataField);
        echo 'OK';
    } catch (Exception $e) {
        echo 'Already exists';
    }
}


// find the correct custom from address
$customFromAddresses = $account->GetCustomFromAddresses();
$customFromAddress = null;
foreach ($customFromAddresses as $cfa) {
    if ('[email protected]' == $cfa->email) {
        $customFromAddress = $cfa;
        break;
    }
}
if (is_null($customFromAddress)) {
    throw new \Exception('Custom from address not found in the account.');
}

// Create campaign to get campaign ID
// we need the campaign id later to create image folder
$campaign = new ApiCampaign();
$campaign->name = 'My API Campaign';
$campaign->subject = 'Api Works';
$campaign->fromName = "Roman Piták";
$campaign->fromAddress = $customFromAddress->toJson();
// empty content (must );
    // set the dotMailer src for the images
    $images[$baseName]['src'] = (string)$apiImage->path;
}

// UPDATE CAMPAIGN
$campaign->id = $campaign->id->toJson();
// getIndexHtml returns the html of the email with the correct src attribute for the images
// it uses the $images array
$htmlContent = getIndexHtml($