PHP code example of markuszeller / cleverreach

1. Go to this page and download the library: Download markuszeller/cleverreach 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/ */

    

markuszeller / cleverreach example snippets


use markuszeller\CleverReach\ApiManager;
use markuszeller\CleverReach\Http\Guzzle as HttpAdapter;

// Create an HTTP adapter
$httpAdapter = new HttpAdapter();

// Authorize your app by credentials
$response = $httpAdapter->authorize('<CLIENT_ID>', '<CLIENT_SECRET>');

if (isset($response['access_token'])) {
    // Persist the access token for later use...
}

use markuszeller\CleverReach\ApiManager;
use markuszeller\CleverReach\Http\Guzzle as HttpAdapter;

// Create an HTTP adapter
$httpAdapter = new HttpAdapter(
    [
        'access_token' => '<ACCESS_TOKEN>',
    ]
);

// Create the API manager
$apiManager = new ApiManager($httpAdapter);

$response = $apiManager->createSubscriber(
    '<EMAIL>',
    '<GROUP_ID>',
    false, // not activated
    [
        'salutation' => 'Mr.',
        'firstname' => 'John',
        'lastname' => 'Doe',
    ]
);

if (isset($response['id'])) {
    // ...
}

$response = $apiManager->triggerDoubleOptInEmail('<EMAIL>', '<FORM_ID>');

if (isset($response['success'])) {
    // ...
}

$response = $apiManager->triggerDoubleOptOutEmail('<EMAIL>', '<FORM_ID>');

if (isset($response['success'])) {
    // ...
}

$response = $apiManager->getSubscriber('<EMAIL>', '<GROUP_ID>');

if (isset($response['id'])) {
    // ...
}

$response = $apiManager->getSubscriber('<EMAIL>', '<GROUP_ID>', '<TRUE_OR_FALSE>');

if (true === $response) {
    // ...
}

$response = $apiManager->deleteSubscriber('<EMAIL>', '<GROUP_ID>');

if (true === $response) {
    // ...
}

// Get a list of all Mailings
// You can provide a state, i.e. draft
$mailings = $apiManager->getMailings(0, ApiManager::MAILING_STATE_DRAFT);

// Get a specific Mailing
// returns a Mailing Object
$mailing = $apiManager->getMailing(MAILING_ID);

// Get Specific Mailing details
$mailingLinks = $apiManager->getMailingLinks(MAILING_ID);
$mailingOrders = $apiManager->getMailingOrders(MAILING_ID);
$mailingChannels = $apiManager->getMailingChannels();
$mailingChannel = $apiManager->getMailingChannel(CHANNEL_ID);

// Read one for updating
$mailing = $apiManager->getMailing(MAILING_ID);

// Create a fresh Mailing and Content instance with no data
$updatedMailing = new Mailing(MAILING_ID);
$content = new MailingContent();

// Get HTML content from "old"
$html = $mailingData->getContent()->getHtml();

// Inject a update message after body tag
$date = date(DATE_W3C);
$html = preg_replace("/(<body.*