goran-popovic/email-octopus-php

v1.0.2 2024-02-04 13:48 UTC

This package is auto-updated.

Last update: 2024-09-04 17:10:56 UTC


README

PHP Email Octopus SDK 是一个 PHP API 客户端,允许您与 Email Octopus 提供的 API 进行交互。使用此包,您可以轻松地将用户订阅/取消订阅您的通讯,触发自动化流程,并查看有关您的活动的各种数据。

支持的 PHP 版本

  • >= 7.2.5

安装

您可以通过 composer 安装此包

composer require goran-popovic/email-octopus-php

入门

API 密钥

在使用 SDK 之前,您需要创建一个 Email Octopus API 密钥

.env 设置

创建密钥后,您可以编辑可能正在使用的任何 .env 文件,并在其中添加您的 API 密钥,例如

EMAIL_OCTOPUS_API_KEY=YOUR_API_KEY

基本实现

然后,您可以像这样与 Email Octopus 的 API 进行交互

$apiKey = getenv('EMAIL_OCTOPUS_API_KEY');

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

$response = $client->lists()->createContact('00000000-0000-0000-0000-000000000000', [
    'email_address' => 'goran.popovic@geoligard.com', // required
    'fields' => [ // optional
        'FirstName' => 'Goran',
        'LastName' => 'Popović',
    ],
    'tags' => [ // optional
        'lead'
    ],
    'status' => 'SUBSCRIBED', // optional
]);

echo $response['status']; // SUBSCRIBED

如果需要,在实例化 Client 时可以设置额外的选项

$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
);

用法

此封装器倾向于遵循官方 Email Octopus API 文档 中的逻辑和分类。所有路由和每个路由的可用参数都在那些文档中进行了更详细的解释。

所有方法都分配到 3 个主要资源中

自动化 资源

您可以在仪表板 URL 中找到当前正在查看的自动化的 ID,如下所示: https://emailoctopus.com/automations/<automationId>

start(string $automationId, array $params)

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

活动 资源

您可以在仪表板 URL 中找到当前正在查看的活动 ID,如下所示: https://emailoctopus.com/reports/campaign/<campaignId>

get(string $campaignId)

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

getAll(array $params = [])

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

getReportSummary(string $campaignId)

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

getReportLinks(string $campaignId)

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

getReportBounced(string $campaignId, array $params)

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

getReportClicked(string $campaignId, array $params)

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

getReportComplained(string $campaignId, array $params)

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

getReportOpened(string $campaignId, array $params)

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

getReportSent(string $campaignId, array $params)

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

getReportUnsubscribed(string $campaignId)

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

getReportNotClicked(string $campaignId, array $params)

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

getReportNotOpened(string $campaignId, array $params)

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

列表 资源

要找到列表 ID,请转到您的 Email Octopus 仪表板,找到 列表 选项卡,通过单击标题选择一个列表,然后在单个列表中打开时转到 设置 选项卡并从中复制 ID。或者,您可以在仪表板 URL 中找到列表或其他资源的 ID,如下所示: https://emailoctopus.com/lists/<listId>

get(string $listId)

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

getAll(array $params = [])

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

create(array $params)

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

update(string $listId, array $params)

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

delete(string $listId)

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

getAllTags(string $listId)

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

getContact(string $listId, string $memberId)

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

getAllContacts(string $listId, array $params = [])

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

getSubscribedContacts(string $listId, array $params = [])

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

getUnsubscribedContacts(string $listId, array $params = [])

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

getContactsByTag(string $listId, string $listTag, array $params = [])

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

createContact(string $listId, array $params)

$client->lists()->createContact('00000000-0000-0000-0000-000000000000', [
    'email_address' => 'goran.popovic@geoligard.com', // required
    'fields' => [ // optional
        'FirstName' => 'Goran',
        'LastName' => 'Popović',
    ],
    'tags' => [ // optional
        'lead'
    ],
    'status' => 'SUBSCRIBED', // optional
]);

updateContact(string $listId, string $memberId, array $params)

注意:对于会员ID,您可以使用在仪表板URL中找到的列表联系人的ID:https://emailoctopus.com/lists/<listId>/contacts/<contactId>,或者列表联系人电子邮件地址的小写版本的MD5哈希值。

$client->lists()->updateContact('00000000-0000-0000-0000-000000000000', md5('goran.popovic@geoligard.com'), [
    'email_address' => 'new_email_address@geoligard.com', // optional
    'fields' => [ // optional
        'FirstName' => 'New name',
        'LastName' => 'New lastname',
    ],
    'tags' => [ // optional
        'vip' => true,
        'lead' => false
    ],
    'status' => 'UNSUBSCRIBED', // optional
]);

deleteContact(string $listId, string $memberId)

注意:对于会员ID,您可以使用在仪表板URL中找到的列表联系人的ID:https://emailoctopus.com/lists/<listId>/contacts/<contactId>,或者列表联系人电子邮件地址的小写版本的MD5哈希值。

$client->lists()->deleteContact(
    '00000000-0000-0000-0000-000000000000',
    md5('goran.popovic@geoligard.com')
);

createField(string $listId, array $params)

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

updateField(string $listId, string $listFieldTag, array $params)

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

deleteField(string $listId, string $listFieldTag)

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

createTag(string $listId, array $params)

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

updateTag(string $listId, string $listTag, array $params)

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

deleteTag(string $listId, string $listTag)

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

变更日志

请参阅变更日志获取有关最近更改的更多信息。