client.Automations
Каждый метод этого пространства имён: его сигнатура, параметры, что он возвращает, и пример.
Методы
Emails and other steps that run by themselves for each contact, such as a welcome series or a birthday note: build a draft from a starter or your own trigger and steps, publish, pause, resume and archive it, send a test, read its versions and statistics, and enroll contacts or take them out.
Automations.ListAutomations.ListAllAutomations.IterateAutomations.CreateAutomations.ListStartersAutomations.GetAutomations.UpdateAutomations.DeleteAutomations.PublishAutomations.PauseAutomations.ResumeAutomations.ArchiveAutomations.DuplicateAutomations.SendTestAutomations.ListVersionsAutomations.RestoreVersionAutomations.StatsAutomations.ListEnrollmentsAutomations.ListAllEnrollmentsAutomations.IterateEnrollmentsAutomations.GetEnrollmentAutomations.EnrollAutomations.ExitEnrollment
Automations.List
List one page of the automations in the workspace
List(ctx context.Context, opts ...openemail.RequestOption) (*openemail.Page, error)Returns one page of the automations the caller can reach, the most recently saved first, without their definitions or settings. Paging is keyset: openemail.WithLimit takes 1 to 100 and defaults to 50, and NextCursor goes back as openemail.WithCursor while HasMore is true. ListAll and Iterate do that walk for you.
Each automation carries its status, triggerKind, how many steps and emails the draft holds, hasUnpublishedChanges, publishedVersion and counts: the contacts in it now, and the ones that completed or left in all its time, counted at the moment of the read. A paused automation says why in pausedReason.
Read one with Get for the draft definition, the published one, the settings and the problems that would stop a publish.
Параметры
openemail.WithStatus...stringOnly automations in this state:
draft,live,pausedorarchived.openemail.WithLimitintRows per page, a whole number from 1 to 100. The server defaults to 50.
openemail.WithCursorstringThe
NextCursorfrom the previous page, passed back exactly as it came. One that names no automation is a 400invalid_cursor.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
A *openemail.Page with Items, HasMore and NextCursor. Each item has id, name, description, status, triggerKind, stepCount, emailCount, hasUnpublishedChanges, publishedVersion, pausedReason, lastError, counts, createdBy, publishedAt, pausedAt, archivedAt, createdAt and updatedAt.
Пример
page, err := client.Automations.List(ctx, openemail.WithStatus("live"))if err != nil { return err} for _, automation := range page.Items { fmt.Printf("%s starts on %s, %d in it now\n", automation.String("name"), automation.String("triggerKind"), automation.Object("counts").Int("active"))} fmt.Println(page.HasMore, page.NextCursor)Примечания
An app a member connected lists only the automations that member made. An API key and an app the owner connected list every automation in the workspace.
Read only, so the SDK retries it after a network failure like any other read.
Также доступно в
Automations.ListAll
Collect every automation you can reach into one slice
ListAll(ctx context.Context, opts ...openemail.RequestOption) ([]openemail.Object, error)Follows NextCursor from page to page and returns with every automation the caller can reach, the most recently saved first, in the shape List returns. openemail.WithLimit sets the page size of each request, not the total.
Параметры
openemail.WithStatus...stringOnly automations in this state:
draft,live,pausedorarchived.openemail.WithLimitintPage size per request, from 1 to 100, defaulting to 50 on the server.
openemail.WithCursorstringA
NextCursorfrom an earlier page to start after.openemail.WithAPIKeystringOverrides the client's API key for every page of this walk.
Возвращает
A []openemail.Object holding every automation across all pages.
Пример
automations, err := client.Automations.ListAll(ctx)if err != nil { return err} for _, automation := range automations { if automation.String("status") == "paused" { fmt.Println(automation.String("name"), automation.String("pausedReason")) }}Примечания
A failure on any page fails the whole call.
Также доступно в
Automations.Iterate
Stream the automations you can reach one at a time
Iterate(ctx context.Context, opts ...openemail.RequestOption) *openemail.IteratorReturns an iterator that yields automations one by one, the most recently saved first, and requests the next page only once the current one is drained. Breaking out of the loop stops the requests.
Параметры
openemail.WithStatus...stringOnly automations in this state:
draft,live,pausedorarchived.openemail.WithLimitintPage size per request, from 1 to 100, defaulting to 50 on the server.
openemail.WithCursorstringA
NextCursorfrom an earlier page to start after.openemail.WithAPIKeystringOverrides the client's API key for every page of this walk.
Возвращает
An *openemail.Iterator yielding one automation per step.
Пример
for automation, err := range client.Automations.Iterate(ctx).All() { if err != nil { return err } if automation.Bool("hasUnpublishedChanges") { fmt.Println("unpublished edits:", automation.String("name")) }}Примечания
The iterator is lazy, so an abandoned loop costs only the pages you consumed.
Также доступно в
Automations.Create
Create an automation as a draft
Create(ctx context.Context, body openemail.Body, opts ...openemail.RequestOption) (openemail.Object, error)Makes a draft automation and returns it whole, in the shape Get returns. Its trigger and steps come from definition when you send one, from the starter named in starter when you do not, and otherwise the draft starts empty. settings changes any of the defaults.
A draft may be incomplete: problems in the answer lists what is still missing, such as a template or a from address a starter leaves for you. Nothing runs until Publish, which needs a complete draft and emails:send.
Параметры
namestringОбязательноWhat the workspace calls the automation, trimmed, 1 to 120 characters. Contacts never see it, and it need not be unique.
descriptionstring | nilA note for the workspace, at most 500 characters. Contacts never see it.
starterstringBegin from a starter, by the
slugListStartersreturns:welcome-series,trial-follow-up,birthdayorwin-back. Ignored whendefinitionis sent. An unknown slug is 422invalid_automation.definitionopenemail.BodyThe trigger and the steps, in the shape
Getreturns asdefinition.triggersays what starts the automation:audience_joinedwithaudienceIdandincludeImported,form_submittedwithformId,eventwitheventNameandfilters,datewithfield,audienceIdandoffsetDays, ormanual.entryis the key of the first step, andstepsholds every step:send_email,wait,branch,add_to_audience,remove_from_audience,update_field,webhookorexit. Each step has a uniquekeyof 3 to 24 lowercase letters and digits starting with a letter, and names the next step by key innext, or inyesandnofor a branch. Null ends the path. Paths never join or loop, and a definition holds at most 50 steps. Leave it out to usestarteror an empty draft.settings.timezonestringThe IANA time zone the sending window and waits until a day and time are read in, such as
Europe/London. Defaults toUTC.settings.sendWindowopenemail.Body | nilWhen emails may go out:
daysof the week, where 0 is Sunday, andstartMinutetoendMinuteof the day, counted from midnight. An email due outside it waits for the window to open. Null, the default, sends at any time.settings.reentryDaysint | nilHow many days after a contact finishes before they may enter again, from 1 to 3650. Null, the default, lets each contact through once only.
settings.exitOnLeaveboolTake a contact out when they leave the audience that started the automation. Defaults to true.
settings.listAudienceIdstring | nilThe audience an unsubscribe from one of these emails is recorded in. Null, the default, uses the audience that starts the automation, or the built-in audience of every contact when no audience starts it. An id that is not an audience of the workspace is 422
invalid_automation.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object: the automation object fields with status draft, plus definition, published, which is null, settings and problems.
Пример
automation, err := client.Automations.Create(ctx, openemail.Body{ "name": "Welcome series", "starter": "welcome-series", "settings": openemail.Body{"timezone": "Europe/London"},})if err != nil { return err} fmt.Println(automation.String("id"), automation.String("status")) for _, problem := range automation.Objects("problems") { fmt.Println(problem.String("path"), problem.String("message"))}Примечания
A value of the wrong type or length is 422
invalid_parameterwithparamnaming it, and a key the body does not take is 422unknown_parameter. A definition that breaks a rule of its structure, such as two steps with one key or two paths into one step, is 422invalid_automation, and theBodyof the error lists each one inproblems, undererror.A workspace holds a limited number of automations, drafts included, and support can raise that for a workspace that needs more. The next one past the limit is 422
workspace_limit_reached.Not retried automatically, and nothing deduplicates by name, so a retry after a lost response can leave two drafts. List them and delete the spare.
Также доступно в
Automations.ListStarters
List the ready-made automations to start from
ListStarters(ctx context.Context, opts ...openemail.RequestOption) ([]openemail.Object, error)Returns the starting points the app offers when somebody makes an automation: a welcome series, a trial follow-up, a birthday note and a win-back. Each comes with its whole definition, so you can read it, change it and send it to Create, or pass its slug to Create as starter.
A starter leaves the audience, the templates and the from address as empty strings for you to fill in. The list is the same for every workspace and is not paginated.
Параметры
openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
A []openemail.Object, each with slug, name, description and definition.
Пример
starters, err := client.Automations.ListStarters(ctx)if err != nil { return err} for _, starter := range starters { fmt.Println(starter.String("slug"), starter.String("description"))}Примечания
Read only, so the SDK retries it after a network failure like any other read.
Также доступно в
Automations.Get
Retrieve an automation with its definition and settings
Get(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Returns the whole automation: the draft definition you edit, published, the definition of the version that is running, settings, fresh counts and problems.
problems is what is wrong with the draft at the moment of the read, each with a code, the path of the field, the stepKey, a message and blocking, which is false for a warning. An empty list means the draft is ready, though Publish checks more: that every template can be sent and that the caller may send from every from address.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object: id, name, description, status, triggerKind, stepCount, emailCount, hasUnpublishedChanges, publishedVersion, pausedReason, lastError, counts, createdBy, publishedAt, pausedAt, archivedAt, createdAt and updatedAt, plus definition, published, settings and problems.
Пример
automation, err := client.Automations.Get(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1")if err != nil { return err} definition := automation.Object("definition") fmt.Println(automation.String("status"), definition.Object("trigger").String("kind"), len(definition.Objects("steps"))) for _, problem := range automation.Objects("problems") { if problem.Bool("blocking") { fmt.Println(problem.String("message")) }}Примечания
An id that names no automation the caller can reach is 404
automation_not_found, whether it does not exist or belongs to another workspace.Read only, so the SDK retries it after a network failure like any other read.
Также доступно в
Automations.Update
Change the draft, the settings or the name of an automation
Update(ctx context.Context, id string, patch openemail.Body, opts ...openemail.RequestOption) (openemail.Object, error)A partial update that returns the automation whole. definition replaces the draft, and a live automation keeps running its published version until you Publish again, so an edit never changes the path of a contact who is halfway through. settings is merged field by field and takes effect at once.
Read the automation, change it and send expectedUpdatedAt with the updatedAt you read. If someone saved it in between, the call is refused with 409 version_conflict instead of writing over their change.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.namestringNew name, trimmed, 1 to 120 characters.
descriptionstring | nilNew note, at most 500 characters. Null clears it.
definitionopenemail.BodyThe new draft, whole. The trigger and the steps, in the shape
Getreturns asdefinition.triggersays what starts the automation:audience_joinedwithaudienceIdandincludeImported,form_submittedwithformId,eventwitheventNameandfilters,datewithfield,audienceIdandoffsetDays, ormanual.entryis the key of the first step, andstepsholds every step:send_email,wait,branch,add_to_audience,remove_from_audience,update_field,webhookorexit. Each step has a uniquekeyof 3 to 24 lowercase letters and digits starting with a letter, and names the next step by key innext, or inyesandnofor a branch. Null ends the path. Paths never join or loop, and a definition holds at most 50 steps.settings.timezonestringThe IANA time zone the sending window and waits until a day and time are read in, such as
Europe/London. Defaults toUTC.settings.sendWindowopenemail.Body | nilWhen emails may go out:
daysof the week, where 0 is Sunday, andstartMinutetoendMinuteof the day, counted from midnight. An email due outside it waits for the window to open. Null, the default, sends at any time.settings.reentryDaysint | nilHow many days after a contact finishes before they may enter again, from 1 to 3650. Null, the default, lets each contact through once only.
settings.exitOnLeaveboolTake a contact out when they leave the audience that started the automation. Defaults to true.
settings.listAudienceIdstring | nilThe audience an unsubscribe from one of these emails is recorded in. Null, the default, uses the audience that starts the automation, or the built-in audience of every contact when no audience starts it. An id that is not an audience of the workspace is 422
invalid_automation.expectedUpdatedAtstringThe
updatedAtyou read, as an ISO 8601 instant. When the automation was saved since, the call is refused with 409version_conflictand nothing is written.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object as it is after the save, with a new updatedAt and, when the draft changed, hasUnpublishedChanges true on a published automation.
Пример
current, err := client.Automations.Get(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1")if err != nil { return err} saved, err := client.Automations.Update(ctx, current.String("id"), openemail.Body{ "settings": openemail.Body{ "sendWindow": openemail.Body{"days": []int{1, 2, 3, 4, 5}, "startMinute": 540, "endMinute": 1020}, }, "expectedUpdatedAt": current.String("updatedAt"),})if err != nil { return err} fmt.Println(saved.Object("settings").Object("sendWindow"), saved.String("updatedAt"))Примечания
An archived automation cannot be changed and answers 409
automation_archived.A value of the wrong type or length is 422
invalid_parameter, a key the patch does not take is 422unknown_parameter, and a definition that breaks a rule of its structure is 422invalid_automation, withproblemsundererrorin theBodyof the error.Retried automatically on network failure and retryable statuses, since saving the same patch twice leaves the same automation. With
expectedUpdatedAt, a retry after a lost response answers 409version_conflict: read the automation to see that your change is there.
Также доступно в
Automations.Delete
Delete an automation with its versions and history
Delete(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Deletes the automation with its versions, its enrollments and its statistics. Contacts in it stop at once and get nothing more. The emails it already sent stay in Emails.List.
There is no undo. To retire an automation and keep its history, use Archive.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with object set to automation, id and deleted set to true.
Пример
removed, err := client.Automations.Delete(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1")if err != nil { return err} fmt.Println(removed.String("id"), removed.Bool("deleted"))Примечания
An OAuth access token needs a verification code for this call, and is refused with 403
step_up_requireduntil the app has verified one in the last 60 minutes. The error matchesopenemail.ErrStepUpRequired. An API key is never asked for a code.The SDK does not retry a delete. A 404 on your own second attempt after a lost response means the first one worked.
Также доступно в
Automations.Publish
Publish the draft and turn the automation on
Publish(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Saves the draft as the next version and sets the automation live, so its trigger starts taking contacts in. Contacts already in it stay on the version they entered on. Publishing a paused automation turns it back on. It takes no body.
The draft has to be complete: a trigger, at least one step, every email with a published template that declares unsubscribeUrl and a from address the caller may send as, and every audience, form and webhook it names still there. Anything else is 422 invalid_automation, and the Body of the error lists every problem that blocks it in problems, under error.
The automation sends as whoever published it. When that API key is revoked, expires or is turned off, the automation pauses itself with pausedReason key_revoked.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with status live, a new publishedAt, the publishedVersion that is now running and hasUnpublishedChanges false.
Пример
automation, err := client.Automations.Publish(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1")if err != nil { return err} fmt.Println(automation.String("status"), automation.Int("publishedVersion"), automation.String("publishedAt"))Примечания
A plan covers a number of live automations: 1 on Free, 10 on Starter and 50 on Business, with no limit on Enterprise. One more is 403
automation_limit_reached. Pause one, or upgrade.An archived automation answers 409
automation_archived.Publishing a draft that has not changed since the last publish keeps the same version number.
Retried automatically on network failure and retryable statuses, since publishing the same draft twice leaves the same live version.
Также доступно в
Automations.Pause
Stop a live automation without losing anybody
Pause(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Stops a live automation. Nobody new enters, and everyone in it stays where they are and moves on when it is resumed. The automation.paused webhook event fires. Pausing a paused automation changes nothing. It takes no body.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with status paused, pausedReason manual and pausedAt set.
Пример
automation, err := client.Automations.Pause(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1")if err != nil { return err} fmt.Println(automation.String("status"), automation.String("pausedReason"), automation.Object("counts").Int("active"))Примечания
A draft that was never published answers 409
automation_not_published, and an archived automation 409automation_archived.Retried automatically on network failure and retryable statuses, since pausing twice leaves the same paused automation.
Также доступно в
Automations.Resume
Turn a paused automation back on
Resume(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Turns a paused automation back on with the version it was running, without publishing the draft. Contacts that were held move on, and from now on it sends as the caller. Resuming a live automation changes nothing. It takes no body.
The published version is checked again first, exactly as Publish checks a draft. An automation OpenEmail paused, because its from address, its templates or an audience went away, stays paused with 422 invalid_automation until what stopped it is fixed.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with status live and pausedReason, pausedAt and lastError cleared.
Пример
automation, err := client.Automations.Resume(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1")if err != nil { return err} fmt.Println(automation.String("status"), automation.Int("publishedVersion"))Примечания
An automation with no published version answers 409
automation_not_published, an archived one 409automation_archived, and a plan that covers no more live automations 403automation_limit_reached.Retried automatically on network failure and retryable statuses, since resuming twice leaves the same live automation.
Также доступно в
Automations.Archive
Retire an automation for good and keep its history
Archive(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Retires an automation. Everyone in it leaves with the exit reason archived, nobody enters again, and it can no longer be changed, published or resumed. Its versions, enrollments and statistics stay readable. Archiving an archived automation changes nothing. It takes no body.
An automation with many contacts in it empties in the background over the next minutes. To start again from its steps, use Duplicate.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with status archived and archivedAt set.
Пример
automation, err := client.Automations.Archive(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1")if err != nil { return err} fmt.Println(automation.String("status"), automation.String("archivedAt"))Примечания
There is no way back from archived. To stop an automation for a while, use
Pause.Retried automatically on network failure and retryable statuses, since archiving twice leaves the same archived automation.
Также доступно в
Automations.Duplicate
Copy an automation into a new draft
Duplicate(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Makes a new draft with the same draft definition and settings, named after the original with (copy) on the end. The copy has no versions, no contacts and no statistics, and it works on an archived automation too. It takes no body.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object for the copy, with its own id and status draft.
Пример
copied, err := client.Automations.Duplicate(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1")if err != nil { return err} fmt.Println(copied.String("id"), copied.String("name"), copied.String("status"))Примечания
A workspace that already holds the most automations it may answers 422
workspace_limit_reached.Not retried automatically, so a retry after a lost response can leave two copies. List them and delete the spare.
Также доступно в
Automations.SendTest
Send yourself the email of one step
SendTest(ctx context.Context, id string, body openemail.Body, opts ...openemail.RequestOption) (openemail.Object, error)Sends the email of one step of the draft to one address, so you can read it before publishing. Contact values are filled from a sample contact, values that come from an event are left empty, and the subject starts with [Test]. It counts toward the monthly sends, is not tracked and enrolls nobody.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.stepKeystringОбязательноThe
keyof the email step to send, from the draftdefinition.tostringWhere the test goes. Left out, it goes to the account email of the person the key or app acts for: the workspace owner for an API key.
openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with automationId, emailId, the email as Emails.Get returns it, to and stepKey.
Пример
test, err := client.Automations.SendTest(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1", openemail.Body{"stepKey": "welcome", "to": "[email protected]"})if err != nil { return err} fmt.Println(test.String("emailId"), test.String("to"))Примечания
A
stepKeythat names no step, a step that is not an email, or a template that cannot be sent is 422invalid_automationwithparamstepKey.The from address of the step has to be one the caller may send as, or the call is refused with 403
from_address_forbidden. A domain that cannot send yet is 409domain_not_sendable, and a plan with no sends left is 429send_quota_exceeded.Not retried automatically, because a retry after a lost response would send the test twice.
Также доступно в
Automations.ListVersions
List the published versions of an automation
ListVersions(ctx context.Context, id string, opts ...openemail.RequestOption) ([]openemail.Object, error)Returns every published version, the newest first, each with its whole definition. current marks the one that is running. A publish that changed the definition adds a version, and each contact stays on the version they entered on. A draft that was never published has none. The list is not paginated.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
A []openemail.Object, each with id, automationId, version, definition, current, createdBy and createdAt.
Пример
versions, err := client.Automations.ListVersions(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1")if err != nil { return err} for _, version := range versions { fmt.Println(version.Int("version"), version.Bool("current"), version.String("createdAt"))}Примечания
Read only, so the SDK retries it after a network failure like any other read.
Также доступно в
Automations.RestoreVersion
Copy an earlier version back into the draft
RestoreVersion(ctx context.Context, id string, version int, opts ...openemail.RequestOption) (openemail.Object, error)Copies the definition of an earlier version into the draft, replacing what the draft holds. Nothing that is running changes until you Publish. It takes no body.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.versionintОбязательноThe number of the version, from
ListVersions. A whole number from 1 up.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with the version in definition, and hasUnpublishedChanges true when it differs from the one that is running.
Пример
automation, err := client.Automations.RestoreVersion(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1", 2)if err != nil { return err} fmt.Println(automation.Bool("hasUnpublishedChanges"), len(automation.Object("definition").Objects("steps")))Примечания
A version the automation does not have is 404
automation_not_foundwithparamversion, and an archived automation is 409automation_archived.Retried automatically on network failure and retryable statuses, since restoring the same version twice leaves the same draft.
Также доступно в
Automations.Stats
Read how an automation has performed
Stats(ctx context.Context, id string, opts ...openemail.RequestOption) (openemail.Object, error)Returns the numbers of an automation over a window: totals for the whole automation, steps with the same numbers step by step, and series with a point for each UTC day on which something happened. The window defaults to the last 30 days and reaches back at most 366 days before openemail.WithUntil.
The steps are those of the published version, or of the draft when nothing is published. totals.active and the waiting of each step are counted at the moment of the read, whatever the window. Opens are a floor, because many mail apps hide them.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithSincetime.TimeWhere the window starts. Left out, 30 days before
openemail.WithUntil.openemail.WithUntiltime.TimeWhere the window ends. Left out, now. It has to be later than
openemail.WithSince.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with automationId, since, until, totals (entered, active, completed, exited, sent, delivered, opened, clicked, bounced, complained and unsubscribed), steps and series.
Пример
stats, err := client.Automations.Stats( ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1", openemail.WithSince(time.Date(2026, time.September, 1, 0, 0, 0, 0, time.UTC)),)if err != nil { return err} totals := stats.Object("totals") fmt.Println(totals.Int("entered"), totals.Int("sent"), totals.Int("clicked")) for _, step := range stats.Objects("steps") { fmt.Println(step.String("stepKey"), step.String("kind"), step.Int("entered"), step.Int("waiting"))}Примечания
An
openemail.WithUntilthat is not afteropenemail.WithSinceis 422invalid_parameter.Read only, so the SDK retries it after a network failure like any other read.
Также доступно в
Automations.ListEnrollments
List one page of the contacts in an automation
ListEnrollments(ctx context.Context, id string, opts ...openemail.RequestOption) (*openemail.Page, error)Returns one page of everyone who is in the automation or has been, the most recent entry first. Each enrollment says who the contact is, the stepKey they are at, whether they are waiting and for which event, what holds a step that is due in heldFor, when they move next in nextRunAt, and how it ended in exitReason.
openemail.WithLimit takes 1 to 200 and defaults to 50. Pass NextCursor back as openemail.WithCursor, with the same filters, while HasMore is true. ListAllEnrollments and IterateEnrollments do that walk for you.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithStatus...stringOnly enrollments in this state:
active,completedorexited.openemail.WithStepKeystringOnly contacts at the step with this
key.openemail.WithQstringOnly contacts whose address or name contains this text, compared without case, up to 200 characters.
openemail.WithLimitintRows per page, a whole number from 1 to 200. The server defaults to 50.
openemail.WithCursorstringThe
NextCursorfrom the previous page, passed back exactly as it came. One that names no enrollment of this automation is a 400invalid_cursor.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
A *openemail.Page with Items, HasMore and NextCursor. Each item has id, automationId, version, contact, status, source, stepKey, waiting, waitingForEvent, heldFor, nextRunAt, exitReason, lastError, startedAt, finishedAt and updatedAt.
Пример
page, err := client.Automations.ListEnrollments(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1", openemail.WithStatus("active"))if err != nil { return err} for _, enrollment := range page.Items { fmt.Println(enrollment.Object("contact").String("email"), enrollment.String("stepKey"), enrollment.String("nextRunAt"))} fmt.Println(page.HasMore, page.NextCursor)Примечания
Read only, so the SDK retries it after a network failure like any other read.
Также доступно в
Automations.ListAllEnrollments
Collect every enrollment of an automation into one slice
ListAllEnrollments(ctx context.Context, id string, opts ...openemail.RequestOption) ([]openemail.Object, error)Follows NextCursor from page to page and returns with every enrollment that matches, the most recent entry first, in the shape ListEnrollments returns. openemail.WithLimit sets the page size of each request, not the total. An automation can hold a great many enrollments, so prefer IterateEnrollments when you do not need them all in memory.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithStatus...stringOnly enrollments in this state:
active,completedorexited.openemail.WithStepKeystringOnly contacts at the step with this
key.openemail.WithQstringOnly contacts whose address or name contains this text, compared without case, up to 200 characters.
openemail.WithLimitintPage size per request, from 1 to 200, defaulting to 50 on the server.
openemail.WithCursorstringA
NextCursorfrom an earlier page to start after.openemail.WithAPIKeystringOverrides the client's API key for every page of this walk.
Возвращает
A []openemail.Object holding every matching enrollment across all pages.
Пример
exited, err := client.Automations.ListAllEnrollments(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1", openemail.WithStatus("exited"), openemail.WithLimit(200))if err != nil { return err} unsubscribed := 0 for _, enrollment := range exited { if enrollment.String("exitReason") == "unsubscribed" { unsubscribed++ }} fmt.Printf("%d of %d left by unsubscribing\n", unsubscribed, len(exited))Примечания
A failure on any page fails the whole call.
Также доступно в
Automations.IterateEnrollments
Stream the enrollments of an automation one at a time
IterateEnrollments(ctx context.Context, id string, opts ...openemail.RequestOption) *openemail.IteratorReturns an iterator that yields enrollments one by one, the most recent entry first, and requests the next page only once the current one is drained. Breaking out of the loop stops the requests.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.openemail.WithStatus...stringOnly enrollments in this state:
active,completedorexited.openemail.WithStepKeystringOnly contacts at the step with this
key.openemail.WithQstringOnly contacts whose address or name contains this text, compared without case, up to 200 characters.
openemail.WithLimitintPage size per request, from 1 to 200, defaulting to 50 on the server.
openemail.WithCursorstringA
NextCursorfrom an earlier page to start after.openemail.WithAPIKeystringOverrides the client's API key for every page of this walk.
Возвращает
An *openemail.Iterator yielding one enrollment per step.
Пример
for enrollment, err := range client.Automations.IterateEnrollments(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1", openemail.WithStatus("active")).All() { if err != nil { return err } if enrollment.String("heldFor") != "" { fmt.Println(enrollment.Object("contact").String("email"), "held for", enrollment.String("heldFor")) }}Примечания
The iterator is lazy, so an abandoned loop costs only the pages you consumed.
Также доступно в
Automations.GetEnrollment
Retrieve one contact's way through an automation
GetEnrollment(ctx context.Context, id string, enrollmentID string, opts ...openemail.RequestOption) (openemail.Object, error)Returns one enrollment with runs: what each step did for the contact, oldest first, up to 200. A run has the stepKey, the kind of step, an outcome such as sent, waited, yes, no, skipped or failed, the emailId a send step produced and a detail that says why a step was skipped or failed.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.enrollmentIDstringОбязательноEnrollment id such as
aen_2b8d4f6a1c3e5079b6d8f0a2, fromListEnrollments.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object: id, automationId, version, contact, status, source, stepKey, waiting, waitingForEvent, heldFor, nextRunAt, exitReason, lastError, startedAt, finishedAt and updatedAt, plus runs.
Пример
enrollment, err := client.Automations.GetEnrollment(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1", "aen_2b8d4f6a1c3e5079b6d8f0a2")if err != nil { return err} for _, run := range enrollment.Objects("runs") { fmt.Println(run.String("createdAt"), run.String("stepKey"), run.String("outcome"), run.String("detail"))}Примечания
An enrollment id that is not in this automation is 404
automation_enrollment_not_found.Read only, so the SDK retries it after a network failure like any other read.
Также доступно в
Automations.Enroll
Put a contact into a live automation
Enroll(ctx context.Context, id string, body openemail.Body, opts ...openemail.RequestOption) (openemail.Object, error)Puts one contact into a live automation at its first step, whatever its trigger is. Name the contact with email or contactId, never both. The contact has to exist already: save one with Contacts.Create first. data gives the steps the values they would otherwise read from an event.
A contact is in an automation once at a time, and comes back in only after settings.reentryDays. An address on the suppression list, or one that unsubscribed from the audience the automation sends through, is refused.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.emailstringThe contact, by email address. Send this or
contactId.contactIdstringThe contact, by id, as an event or another enrollment carries it. Send this or
email.dataopenemail.BodyValues the steps can read wherever a value comes from the event, such as an order number for an email. At most 50 keys and 4 KB of JSON.
openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with status active, source api and nextRunAt now. The first step runs within about a minute.
Пример
enrollment, err := client.Automations.Enroll( ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1", openemail.Body{"email": "[email protected]", "data": openemail.Body{"plan": "team"}},)if err != nil { return err} fmt.Println(enrollment.String("id"), enrollment.String("status"), enrollment.String("nextRunAt"))Примечания
An automation that is a draft, paused or archived answers 409
automation_not_live. A contact who is in it, or finished it too recently, answers 409already_enrolled, and a suppressed or unsubscribed address 409contact_unreachable. An address or id nobody has is 404contact_not_found.Sending neither or both of
emailandcontactIdis 422invalid_parameter.Not retried automatically. After a lost response, a second attempt that answers 409
already_enrolledmeans the first one worked.
Также доступно в
Automations.ExitEnrollment
Take a contact out of an automation
ExitEnrollment(ctx context.Context, id string, enrollmentID string, opts ...openemail.RequestOption) (openemail.Object, error)Ends an active enrollment at once with the exit reason removed. The contact gets nothing more from this automation, and stays in the contacts and in their audiences. It takes no body.
Параметры
idstringОбязательноAutomation id such as
aut_5c1e9a7b3d2f48e6a0b4c7d1.enrollmentIDstringОбязательноEnrollment id such as
aen_2b8d4f6a1c3e5079b6d8f0a2, fromListEnrollments.openemail.WithAPIKeystringOverrides the client's API key for this call only.
Возвращает
An openemail.Object with status exited, exitReason removed and finishedAt set.
Пример
enrollment, err := client.Automations.ExitEnrollment(ctx, "aut_5c1e9a7b3d2f48e6a0b4c7d1", "aen_2b8d4f6a1c3e5079b6d8f0a2")if err != nil { return err} fmt.Println(enrollment.String("status"), enrollment.String("exitReason"), enrollment.String("finishedAt"))Примечания
An enrollment that already completed or left answers 409
automation_enrollment_finished.Not retried automatically. After a lost response, a second attempt that answers 409
automation_enrollment_finishedmeans the first one worked.