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

オートメーション

`automations.list`、`get`、`create`、`update`、`publish`、`pause`、`resume`、`archive`、`duplicate`、`delete`、`sendTest`、`stats`、`listVersions`、`restoreVersion`、`listStarters`、`listEnrollments`、`getEnrollment`、`enroll`、`exitEnrollment`、そして `events.send`、`sendBatch`、`listNames`。

すべてのメソッド

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)

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

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

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