PHP code example of goran-popovic / email-octopus-php

1. Go to this page and download the library: Download goran-popovic/email-octopus-php 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/ */

    

goran-popovic / email-octopus-php example snippets


$apiKey = getenv('EMAIL_OCTOPUS_API_KEY');

$client = EmailOctopus::client($apiKey);

$response = $client->lists()->createContact('00000000-0000-0000-0000-000000000000', [
    'email_address' => '[email protected]', //  SUBSCRIBED

$client = EmailOctopus::client(
    $apiKey,
    'https://emailoctopus.com/api/1.6/', // API base URI, for most cases default is fine and there is no need to set this variable
    30, // timeout - maximum number of seconds to wait for a response
    3 // connect timeout - maximum number of seconds to wait while trying to connect to a server
);

$client->automations()->start('00000000-0000-0000-0000-000000000000', [ 
    'list_member_id' => '00000000-0000-0000-0000-000000000000', 
]);

$client->campaigns()->get('00000000-0000-0000-0000-000000000000');

$client->campaigns()->getAll([
    'limit' => 1, // optional 
    'page' => 2 // optional 
]);

$client->campaigns()->getReportSummary('00000000-0000-0000-0000-000000000000');

$client->campaigns()->getReportLinks('00000000-0000-0000-0000-000000000000');

$client->campaigns()->getReportBounced('00000000-0000-0000-0000-000000000000', [
    'limit' => 1 // optional 
]);

$client->campaigns()->getReportClicked('00000000-0000-0000-0000-000000000000', [
    'limit' => 1 // optional 
]);

$client->campaigns()->getReportComplained('00000000-0000-0000-0000-000000000000', [
    'limit' => 1 // optional 
]);

$client->campaigns()->getReportOpened('00000000-0000-0000-0000-000000000000', [
    'limit' => 1 // optional 
]);

$client->campaigns()->getReportSent('00000000-0000-0000-0000-000000000000', [
    'limit' => 1 // optional 
]);

$client->campaigns()->getReportUnsubscribed('00000000-0000-0000-0000-000000000000');

$client->campaigns()->getReportNotClicked('00000000-0000-0000-0000-000000000000', [
    'limit' => 1 // optional 
]);

$client->campaigns()->getReportNotOpened('00000000-0000-0000-0000-000000000000', [
    'limit' => 1 // optional 
]);

$client->lists()->get('00000000-0000-0000-0000-000000000000');

$client->lists()->getAll([
    'limit' => 1, // optional
    'page' => 2 // optional
]);

$client->lists()->create([
    'name' => 'Api test'
]);

$client->lists()->update('00000000-0000-0000-0000-000000000000', [
    'name' => 'New name'
]);

$client->lists()->delete('00000000-0000-0000-0000-000000000000');

$client->lists()->getAllTags('00000000-0000-0000-0000-000000000000');

$client->lists()->getContact(
    '00000000-0000-0000-0000-000000000000', 
    '00000000-0000-0000-0000-000000000000', 
);

$client->lists()->getAllContacts('00000000-0000-0000-0000-000000000000', [
    'limit' => 1, // optional
    'page' => 2 // optional
]);

$client->lists()->getSubscribedContacts('00000000-0000-0000-0000-000000000000', [
    'limit' => 1, // optional
    'page' => 2 // optional
]);

$client->lists()->getUnsubscribedContacts('00000000-0000-0000-0000-000000000000', [
    'limit' => 1, // optional
    'page' => 2 // optional
]);

$client->lists()->getContactsByTag('00000000-0000-0000-0000-000000000000', 'lead', [
    'limit' => 1
]);

$client->lists()->createContact('00000000-0000-0000-0000-000000000000', [
    'email_address' => '[email protected]', // 
        'lead'
    ],
    'status' => 'SUBSCRIBED', // optional
]);

$client->lists()->updateContact('00000000-0000-0000-0000-000000000000', md5('[email protected]'), [
    'email_address' => '[email protected]', // optional
    'fields' => [ // optional
        'FirstName' => 'New name',
        'LastName' => 'New lastname',
    ],
    'tags' => [ // optional
        'vip' => true,
        'lead' => false
    ],
    'status' => 'UNSUBSCRIBED', // optional
]);

$client->lists()->deleteContact(
    '00000000-0000-0000-0000-000000000000',
    md5('[email protected]')
);

$client->lists()->createField('00000000-0000-0000-0000-000000000000', [
    'label' => 'What is your hometown?',
    'tag' => 'Hometown',
    'type' => 'TEXT',
    'fallback' => 'Unknown' // optional
]);

$client->lists()->updateField('00000000-0000-0000-0000-000000000000', 'Hometown', [
    'label' => 'New label',
    'tag' => 'NewTag',
    'fallback' => 'New fallback' // optional
]);

$client->lists()->deleteField('00000000-0000-0000-0000-000000000000', 'NewTag');

$client->lists()->createTag('00000000-0000-0000-0000-000000000000', [
    'tag' => 'vip'
]);

$client->lists()->updateTag('00000000-0000-0000-0000-000000000000', 'vip', [
    'tag' => 'New Tag Name'
]);

$client->lists()->deleteTag('00000000-0000-0000-0000-000000000000', 'New Tag Name');
text
EMAIL_OCTOPUS_API_KEY=YOUR_API_KEY