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

オートメーション

`automations.list`、`get`、`create`、`update`、`publish`、`pause`、`resume`、`archive`、`duplicate`、`delete`、`send_test`、`stats`、`list_versions`、`restore_version`、`list_starters`、`list_enrollments`、`get_enrollment`、`enroll`、`exit_enrollment`、そして `events.send`、`send_batch`、`list_names`。

すべてのメソッド

automations.py
from openemail import openemail automation = openemail.automations.create({    'name': 'Welcome series',    'starter': 'welcome-series',    'settings': {'timezone': 'Europe/London'},}) saved = openemail.automations.update(automation['id'], {    'definition': {        **automation['definition'],        'trigger': {'kind': 'event', 'eventName': 'trial.started', 'filters': []},    },    'expectedUpdatedAt': automation['updatedAt'],}) blocking = [problem for problem in saved['problems'] if problem['blocking']]if blocking:    raise RuntimeError(blocking[0]['message']) openemail.automations.send_test(saved['id'], {'stepKey': saved['definition']['entry'] or ''})live = openemail.automations.publish(saved['id']) sent = openemail.events.send(    {        'name': 'trial.started',        'email': '[email protected]',        'properties': {'plan': 'starter'},        'createContact': True,    },    idempotency_key='trial:[email protected]',) for enrollment in openemail.automations.iterate_enrollments(live['id'], status='active'):    if enrollment['heldFor']:        print(enrollment['contact']['email'], enrollment['heldFor']) stats = openemail.automations.stats(live['id'])history = openemail.contacts.list_events('[email protected]', name='trial.started') openemail.automations.pause(live['id'])openemail.automations.resume(live['id']) print(sent['enrolled'], stats['totals']['entered'], len(history['items']))

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

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

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

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

リファレンス