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

オートメーション

`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`、`exit_enrollment`、そして `events.send`、`send_batch`、`list_names`。

すべてのメソッド

automations.rb
automation = client.automations.create(  name: "Welcome series",  starter: "welcome-series",  settings: {timezone: "Europe/London"}) trigger = {kind: "event", eventName: "trial.started", filters: []}saved = client.automations.update(  automation[:id],  definition: automation[:definition].to_h.merge(trigger: trigger),  expectedUpdatedAt: automation[:updatedAt]) blocking = saved[:problems].to_a.find { |problem| problem[:blocking] }raise blocking[:message] if blocking client.automations.send_test(saved[:id], stepKey: saved.dig(:definition, :entry))live = client.automations.publish(saved[:id]) sent = client.events.send(  name: "trial.started",  email: "[email protected]",  properties: {plan: "starter"},  createContact: true,  idempotency_key: "trial:[email protected]") client.automations.iterate_enrollments(live[:id], status: "active") do |enrollment|  puts "#{enrollment.dig(:contact, :email)} #{enrollment[:heldFor]}" if enrollment[:heldFor]end stats = client.automations.stats(live[:id])history = client.contacts.list_events("[email protected]", name: "trial.started") client.automations.pause(live[:id])client.automations.resume(live[:id]) puts sent[:enrolled], stats.dig(:totals, :entered), history.items.size

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

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

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

連絡先の attributes にはカスタム項目が入り、オートメーションはその 1 つを attributes.<key> として読み取ります。