Zur Dokumentation springen
TypeScript

Automatisierungen

`automations.list`, `get`, `create`, `update`, `publish`, `pause`, `resume`, `archive`, `duplicate`, `delete`, `sendTest`, `stats`, `listVersions`, `restoreVersion`, `listStarters`, `listEnrollments`, `getEnrollment`, `enroll` und `exitEnrollment`, dazu `events.send`, `sendBatch` und `listNames`.

Jede Methode

automations.ts
const automation = await openemail.automations.create({  name: 'Welcome series',  starter: 'welcome-series',  settings: { timezone: 'Europe/London' },}) const saved = await openemail.automations.update(automation.id, {  definition: { ...automation.definition, trigger: { kind: 'event', eventName: 'trial.started', filters: [] } },  expectedUpdatedAt: automation.updatedAt,}) if (saved.problems.some((problem) => problem.blocking)) throw new Error(saved.problems[0]?.message) await openemail.automations.sendTest(saved.id, { stepKey: saved.definition.entry ?? '' })const live = await openemail.automations.publish(saved.id) const sent = await openemail.events.send(  { name: 'trial.started', email: '[email protected]', properties: { plan: 'starter' }, createContact: true },  { idempotencyKey: 'trial:[email protected]' },) for await (const enrollment of openemail.automations.iterateEnrollments(live.id, { status: 'active' })) {  if (enrollment.heldFor) console.log(enrollment.contact.email, enrollment.heldFor)} const stats = await openemail.automations.stats(live.id)const history = await openemail.contacts.listEvents('[email protected]', { name: 'trial.started' }) await openemail.automations.pause(live.id)await openemail.automations.resume(live.id) console.log(sent.enrolled, stats.totals.entered, history.items.length)

Eine Automatisierung hat einen Entwurf in definition und die Version in published, die läuft. update ändert den Entwurf und die Einstellungen, und publish friert den Entwurf als nächste Version ein und schaltet die Automatisierung ein. problems sagt, was der Veröffentlichung eines Entwurfs noch im Weg steht, und expectedUpdatedAt lehnt eine Speicherung, die die einer anderen Person überschreiben würde, mit 409 version_conflict ab.

Lesen erfordert automations:read und Ändern erfordert automations:write. publish, resume und sendTest erfordern außerdem emails:send. events.send und events.sendBatch erfordern contacts:write, und contacts.listEvents erfordert contacts:read. delete verlangt von einem OAuth-Zugriffstoken einen Bestätigungscode, von einem API-Schlüssel nie.

events.sendBatch nimmt bis zu 100 Ereignisse und wirft wegen eines einzelnen fehlerhaften Ereignisses nie einen Fehler: Die Antwort listet accepted und failed auf, jeweils mit dem index des Ereignisses im gesendeten Array.