Email Octopus SDK for Laravel is a PHP API client that allows you to interact with the API provided by Email Octopus. Using the package you can easily subscribe/unsubscribe users to your newsletter, trigger automations and view various data about your campaigns.
Note
This repository contains the code that is most suited to be used with Laravel framework.
If you want to use the PHP API client in a framework-agnostic way,
check out the goran-popovic/email-octopus-php
repository.
- >= 7.2.5
- >= 7.29.0
You can install the package via composer:
composer require goran-popovic/email-octopus-laravel
If you wish to publish the config file to config/email-octopus.php
run:
php artisan vendor:publish --tag="email-octopus-config"
Before being able to use the SDK, you would need to create an Email Octopus API key.
After creating the key by following the instructions above, edit your .env
file and add the API key there:
EMAIL_OCTOPUS_API_KEY=YOUR_API_KEY
Package will register a Facade that you can use in your app to make API calls, just make sure to include it at the top of the file:
use GoranPopovic\EmailOctopus\Facades\EmailOctopus;
Then, you can interact with Email Octopus's API like so:
use GoranPopovic\EmailOctopus\Facades\EmailOctopus;
$response = EmailOctopus::lists()->createContact('00000000-0000-0000-0000-000000000000', [
'email_address' => '[email protected]', // required
'fields' => [ // optional
'FirstName' => 'Goran',
'LastName' => 'Popović',
],
'tags' => [ // optional
'lead'
],
'status' => 'SUBSCRIBED', // optional
]);
echo $response['status']; // SUBSCRIBED
Other available config settings include the ability to set the base URI of the API, timeout and connect timeout.
For most use cases the defaults are just fine, but if you want, you can set those params
in either the config file (config/email-octopus
) or by using environment variables.
This wrapper tends to follow the logic and classification found in the official Email Octopus API docs. All the routes, and available params for each route are explained in greater detail in those docs.
All the methods are assigned into 3 main resources:
You can find an ID of the automation you are currently viewing in the dashboard URL,
like so: https://emailoctopus.com/automations/<automationId>
EmailOctopus::automations()->start('00000000-0000-0000-0000-000000000000', [
'list_member_id' => '00000000-0000-0000-0000-000000000000',
]);
You can find an ID of the campaign you are currently viewing in the dashboard URL,
like so: https://emailoctopus.com/reports/campaign/<campaignId>
EmailOctopus::campaigns()->get('00000000-0000-0000-0000-000000000000');
EmailOctopus::campaigns()->getAll([
'limit' => 1, // optional
'page' => 2 // optional
]);
EmailOctopus::campaigns()->getReportSummary('00000000-0000-0000-0000-000000000000');
EmailOctopus::campaigns()->getReportLinks('00000000-0000-0000-0000-000000000000');
EmailOctopus::campaigns()->getReportBounced('00000000-0000-0000-0000-000000000000', [
'limit' => 1 // optional
]);
EmailOctopus::campaigns()->getReportClicked('00000000-0000-0000-0000-000000000000', [
'limit' => 1 // optional
]);
EmailOctopus::campaigns()->getReportComplained('00000000-0000-0000-0000-000000000000', [
'limit' => 1 // optional
]);
EmailOctopus::campaigns()->getReportOpened('00000000-0000-0000-0000-000000000000', [
'limit' => 1 // optional
]);
EmailOctopus::campaigns()->getReportSent('00000000-0000-0000-0000-000000000000', [
'limit' => 1 // optional
]);
EmailOctopus::campaigns()->getReportUnsubscribed('00000000-0000-0000-0000-000000000000');
EmailOctopus::campaigns()->getReportNotClicked('00000000-0000-0000-0000-000000000000', [
'limit' => 1 // optional
]);
EmailOctopus::campaigns()->getReportNotOpened('00000000-0000-0000-0000-000000000000', [
'limit' => 1 // optional
]);
To find the list ID, go to your Email Octopus dashboard, find the Lists
tab,
select a list by clicking on its title, and when you open a single list simply go to the settings
tab
and copy the ID from there. Alternatively, you can find an ID of the list or any other resource
you are currently viewing in the dashboard URL, like so: https://emailoctopus.com/lists/<listId>
EmailOctopus::lists()->get('00000000-0000-0000-0000-000000000000');
EmailOctopus::lists()->getAll([
'limit' => 1, // optional
'page' => 2 // optional
]);
EmailOctopus::lists()->create([
'name' => 'Api test'
]);
EmailOctopus::lists()->update('00000000-0000-0000-0000-000000000000', [
'name' => 'New name'
]);
EmailOctopus::lists()->delete('00000000-0000-0000-0000-000000000000');
EmailOctopus::lists()->getAllTags('00000000-0000-0000-0000-000000000000');
EmailOctopus::lists()->getContact(
'00000000-0000-0000-0000-000000000000',
'00000000-0000-0000-0000-000000000000',
);
EmailOctopus::lists()->getAllContacts('00000000-0000-0000-0000-000000000000', [
'limit' => 1, // optional
'page' => 2 // optional
]);
EmailOctopus::lists()->getSubscribedContacts('00000000-0000-0000-0000-000000000000', [
'limit' => 1, // optional
'page' => 2 // optional
]);
EmailOctopus::lists()->getUnsubscribedContacts('00000000-0000-0000-0000-000000000000', [
'limit' => 1, // optional
'page' => 2 // optional
]);
EmailOctopus::lists()->getContactsByTag('00000000-0000-0000-0000-000000000000', 'lead', [
'limit' => 1
]);
EmailOctopus::lists()->createContact('00000000-0000-0000-0000-000000000000', [
'email_address' => '[email protected]', // required
'fields' => [ // optional
'FirstName' => 'Goran',
'LastName' => 'Popović',
],
'tags' => [ // optional
'lead'
],
'status' => 'SUBSCRIBED', // optional
]);
Note: For member ID you can either use the ID of the list contact that you can find in the URL in the dashboard:
https://emailoctopus.com/lists/<listId>/contacts/<contactId>
,
or an MD5 hash of the lowercase version of the list contact's email address.
EmailOctopus::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
]);
Note: For member ID you can either use the ID of the list contact that you can find in the URL in the dashboard:
https://emailoctopus.com/lists/<listId>/contacts/<contactId>
,
or an MD5 hash of the lowercase version of the list contact's email address.
EmailOctopus::lists()->deleteContact(
'00000000-0000-0000-0000-000000000000',
md5('[email protected]')
);
EmailOctopus::lists()->createField('00000000-0000-0000-0000-000000000000', [
'label' => 'What is your hometown?',
'tag' => 'Hometown',
'type' => 'TEXT',
'fallback' => 'Unknown' // optional
]);
EmailOctopus::lists()->updateField('00000000-0000-0000-0000-000000000000', 'Hometown', [
'label' => 'New label',
'tag' => 'NewTag',
'fallback' => 'New fallback' // optional
]);
EmailOctopus::lists()->deleteField('00000000-0000-0000-0000-000000000000', 'NewTag');
EmailOctopus::lists()->createTag('00000000-0000-0000-0000-000000000000', [
'tag' => 'vip'
]);
EmailOctopus::lists()->updateTag('00000000-0000-0000-0000-000000000000', 'vip', [
'tag' => 'New Tag Name'
]);
EmailOctopus::lists()->deleteTag('00000000-0000-0000-0000-000000000000', 'New Tag Name');
Please see CHANGELOG for more information on what has changed recently.