Перейти к документации
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 событий и никогда не выбрасывает исключение из-за одного плохого события: ответ перечисляет accepted и failed, каждое с index события в отправленном вами списке.

В attributes контакта лежат свои поля, а автоматизация читает любое из них как attributes.<key>.

Справочник