ドキュメント本文へスキップ
PHP

オートメーション

`automations->list`、`get`、`create`、`update`、`publish`、`pause`、`resume`、`archive`、`duplicate`、`delete`、`sendTest`、`stats`、`listVersions`、`restoreVersion`、`listStarters`、`listEnrollments`、`getEnrollment`、`enroll`、`exitEnrollment`、そして `events->send`、`sendBatch`、`listNames`。

すべてのメソッド

automations.php
use OpenEmail\Constants\AutomationEnrollmentStatuses;use OpenEmail\Constants\AutomationTriggerKinds; $automation = $client->automations->create([    'name' => 'Welcome series',    'starter' => 'welcome-series',    'settings' => ['timezone' => 'Europe/London'],]); $definition = $automation['definition'];$definition['trigger'] = ['kind' => AutomationTriggerKinds::EVENT, 'eventName' => 'trial.started', 'filters' => []]; $saved = $client->automations->update($automation['id'], [    'definition' => $definition,    'expectedUpdatedAt' => $automation['updatedAt'],]); foreach ($saved['problems'] as $problem) {    if ($problem['blocking']) {        throw new \RuntimeException($problem['message']);    }} $client->automations->sendTest($saved['id'], ['stepKey' => $saved['definition']['entry'] ?? '']);$live = $client->automations->publish($saved['id']); $sent = $client->events->send([    'name' => 'trial.started',    'email' => '[email protected]',    'properties' => ['plan' => 'starter'],    'createContact' => true,], idempotencyKey: 'trial:[email protected]'); foreach ($client->automations->iterateEnrollments($live['id'], status: AutomationEnrollmentStatuses::ACTIVE) as $enrollment) {    if ($enrollment['heldFor'] !== null) {        echo $enrollment['contact']['email'], ' ', $enrollment['heldFor'], PHP_EOL;    }} $stats = $client->automations->stats($live['id']);$history = $client->contacts->listEvents('[email protected]', name: 'trial.started'); $client->automations->pause($live['id']);$client->automations->resume($live['id']); echo count($sent['enrolled']), ' ', $stats['totals']['entered'], ' ', count($history->items), PHP_EOL;

オートメーションは、下書きの definition と、実行される published バージョンを持ちます。update は下書きと設定を変更し、publish は下書きを次のバージョンとして確定してオートメーションを有効にします。problems は、下書きの公開をまだ妨げているものを示し、expectedUpdatedAt は、ほかの人の保存を上書きしてしまう保存を 409 version_conflict で拒否します。

読み取りには automations:read、変更には automations:write が必要です。publish、resume、sendTest には emails:send も必要です。events->send と events->sendBatch には contacts:write、contacts->listEvents には contacts:read が必要です。delete では OAuth アクセストークンに確認コードが求められ、API キーに求められることはありません。

events->sendBatch は最大 100 件のイベントを受け取り、不正なイベントが 1 件あっても例外をスローしません。レスポンスには accepted と failed が並び、それぞれに、送信した配列内でのイベントの index が付きます。

連絡先の attributes にはカスタム項目が入り、オートメーションはその 1 つを attributes.<key> として読み取ります。