---
title: "Automations"
description: "`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` and `exit_enrollment`, with `events.send`, `send_batch` and `list_names`."
url: "https://openemail.uk/docs/python/automations"
area: "Python"
category: "Mailbox"
---

# Automations

`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` and `exit_enrollment`, with `events.send`, `send_batch` and `list_names`.

## Every method

**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': 'ann@example.com',
        'properties': {'plan': 'starter'},
        'createContact': True,
    },
    idempotency_key='trial:ann@example.com',
)

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('ann@example.com', name='trial.started')

openemail.automations.pause(live['id'])
openemail.automations.resume(live['id'])

print(sent['enrolled'], stats['totals']['entered'], len(history['items']))
```

An automation keeps a draft `definition` and the `published` version that runs. `update` changes the draft and the settings, and `publish` freezes the draft as the next version and turns the automation on. `problems` says what still stops a draft from being published, and `expectedUpdatedAt` refuses a save that would overwrite someone else’s with 409 `version_conflict`.

Reading needs `automations:read` and changing needs `automations:write`. `publish`, `resume` and `send_test` also need `emails:send`. `events.send` and `events.send_batch` need `contacts:write`, and `contacts.list_events` needs `contacts:read`. `delete` asks an OAuth access token for a verification code, and an API key never.

`events.send_batch` takes up to 100 events and never raises for one bad event: the answer lists `accepted` and `failed`, each with the `index` of the event in the list you sent.

`attributes` on a contact holds its custom fields, and an automation reads one as `attributes.<key>`.

## Reference

- [`automations.list()`](https://openemail.uk/docs/python/reference/automations#list): full reference
- [`automations.list_all()`](https://openemail.uk/docs/python/reference/automations#listAll): full reference
- [`automations.iterate()`](https://openemail.uk/docs/python/reference/automations#iterate): full reference
- [`automations.get()`](https://openemail.uk/docs/python/reference/automations#get): full reference
- [`automations.create()`](https://openemail.uk/docs/python/reference/automations#create): full reference
- [`automations.update()`](https://openemail.uk/docs/python/reference/automations#update): full reference
- [`automations.delete()`](https://openemail.uk/docs/python/reference/automations#delete): full reference
- [`automations.publish()`](https://openemail.uk/docs/python/reference/automations#publish): full reference
- [`automations.pause()`](https://openemail.uk/docs/python/reference/automations#pause): full reference
- [`automations.resume()`](https://openemail.uk/docs/python/reference/automations#resume): full reference
- [`automations.archive()`](https://openemail.uk/docs/python/reference/automations#archive): full reference
- [`automations.duplicate()`](https://openemail.uk/docs/python/reference/automations#duplicate): full reference
- [`automations.send_test()`](https://openemail.uk/docs/python/reference/automations#sendTest): full reference
- [`automations.stats()`](https://openemail.uk/docs/python/reference/automations#stats): full reference
- [`automations.list_versions()`](https://openemail.uk/docs/python/reference/automations#listVersions): full reference
- [`automations.restore_version()`](https://openemail.uk/docs/python/reference/automations#restoreVersion): full reference
- [`automations.list_starters()`](https://openemail.uk/docs/python/reference/automations#listStarters): full reference
- [`automations.list_enrollments()`](https://openemail.uk/docs/python/reference/automations#listEnrollments): full reference
- [`automations.list_all_enrollments()`](https://openemail.uk/docs/python/reference/automations#listAllEnrollments): full reference
- [`automations.iterate_enrollments()`](https://openemail.uk/docs/python/reference/automations#iterateEnrollments): full reference
- [`automations.get_enrollment()`](https://openemail.uk/docs/python/reference/automations#getEnrollment): full reference
- [`automations.enroll()`](https://openemail.uk/docs/python/reference/automations#enroll): full reference
- [`automations.exit_enrollment()`](https://openemail.uk/docs/python/reference/automations#exitEnrollment): full reference
- [`events.send()`](https://openemail.uk/docs/python/reference/events#send): full reference
- [`events.send_batch()`](https://openemail.uk/docs/python/reference/events#sendBatch): full reference
- [`events.list_names()`](https://openemail.uk/docs/python/reference/events#listNames): full reference
- [`contacts.list_events()`](https://openemail.uk/docs/python/reference/contacts#listEvents): full reference
- [`contacts.list_all_events()`](https://openemail.uk/docs/python/reference/contacts#listAllEvents): full reference
- [`contacts.iterate_events()`](https://openemail.uk/docs/python/reference/contacts#iterateEvents): full reference
