Belgelere geç
TypeScript

Otomasyonlar

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

Her yöntem

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)

Bir otomasyon bir taslak definition ve çalışan published sürümü tutar. update taslağı ve ayarları değiştirir, publish ise taslağı sonraki sürüm olarak dondurur ve otomasyonu etkinleştirir. problems, bir taslağın yayımlanmasını hâlâ neyin engellediğini söyler, expectedUpdatedAt ise başka birinin kaydının üzerine yazacak bir kaydı 409 version_conflict ile reddeder.

Okumak automations:read, değiştirmek automations:write gerektirir. publish, resume ve sendTest ayrıca emails:send gerektirir. events.send ve events.sendBatch için contacts:write, contacts.listEvents için contacts:read gerekir. delete, bir OAuth erişim tokenından doğrulama kodu ister, bir API anahtarından ise asla istemez.

events.sendBatch en fazla 100 olay alır ve tek bir hatalı olay için asla hata fırlatmaz: yanıt accepted ve failed listelerini verir, her biri olayın gönderdiğiniz dizideki index değeriyle.