Skip to main content
Use these recipes when your application or agent sends emails or manages automations through the SDK. You supply the trigger contract and graph; emails.generate() creates the email content.

Build a Welcome Automation

Start with a configured brand and a verified marketing domain. Set BREW_API_KEY to a brand key and BREW_DOMAIN_ID to the intended domain. For an organization key, pin a brand first.
The automation starts as a draft. Creating it sends nothing. Keep the returned IDs for the following steps. SDK Resources lists node and request conventions.

Test Before Publishing

Continue with the client and automation above. Omit testRecipient for a run that sends no mail.
Repeat the run read until it finishes. Test waits fast-forward. Adding testRecipient delivers test emails to that address. Inspect testCoverage for paths the run did not visit; use scenario to simulate engagement or force split branches. After reviewing the test, publish and check readiness:
Publishing enables future trigger events to start runs. The SDK applies the change directly. Readiness checks the credential and published automations without firing.

Fire from Your Backend

Send the real event payload after publishing. Use one retry key per source event.
This starts live runs. The recipient must have opted in for marketing. For transactional flows, choose a transactional-purpose domain and a suitable event such as an order or password reset. Inspect the fire with automations.triggerInstances.get(fire.triggerInstanceId). Read each started run with automations.runs.get(runId, { include: 'logs' }). The retry key is a request option; Idempotency owns replay behavior.

Reuse a Saved Design

Search ready designs before generating another one:
The list returns one page. Pagination explains how to inspect further pages.

Send to an Audience

With a configured brew client, choose a ready design, a verified marketing domain, and an opted-in audience. Replace the IDs below and send yourself a test before launching:
This starts a production send directly. Keep sendId for brew.sends.get(sendId). pending_approval means an administrator must approve the send before delivery. Monitor Email Sends owns statuses and delivery results.

Edit a Published Graph

Use automations.patch({ automationId, nodes, connections }) to save graph edits as a draft. Then publish that version with automations.publish({ automationId, automationVersionId }). Graph edits and published cannot share one patch request. The existing live version continues until you publish the new one. For manual-audience flows, use automations.run({ automationId, dryRun: true }) to preview, then omit dryRun to launch. Keep the returned audienceRunId for audienceRuns.pause(), resume(), or cancel(). See Error Handling and the Error Catalog for recovery.

Need Help?

Our team is ready to support you at every step of your journey with Brew. Choose the option that works best for you:

Search Documentation

Type in the “Ask any question” search bar at the top left to instantly find relevant documentation pages.

Ask ChatGPT or Claude

Click here to open the Copy page menu at the top of this page, then send the page to ChatGPT, Claude, or your editor.