Marketing Automations
Relevant source files
The following files were used as context for generating this wiki page:
- src/main/java/com/resend/services/automations/Automations.java
- src/main/java/com/resend/services/automations/model/Automation.java
- src/main/java/com/resend/services/automations/model/AbstractStepBuilder.java
- src/main/java/com/resend/services/automations/model/AutomationStep.java
- src/main/java/com/resend/services/automations/model/CreateAutomationOptions.java
- src/main/java/com/resend/services/automations/model/AutomationRun.java
- src/main/java/com/resend/services/automations/model/ListAutomationsParams.java
Marketing Automations allow you to create, manage, and monitor automated workflows triggered by specific events. These workflows consist of a series of steps and connections that define how the system responds to triggers, such as user signups or contact updates.
Sources: src/main/java/com/resend/services/automations/Automations.java:13, src/test/java/com/resend/services/util/AutomationsUtil.java:15-30
Service Architecture
The Automations class provides the primary interface for interacting with the Resend Automations API. It extends BaseService to handle authentication and HTTP communication.
core Operations
The service supports several management operations:
- Create: Initialize a new automation with a name, status, steps, and connections.
- Retrieve: Fetch details of a specific automation using its ID.
- List: Query automations with support for filtering by status and pagination.
- Update: Modify existing automation configurations.
- Control: Stop, duplicate, or remove existing automations.
Sources: src/main/java/com/resend/services/automations/Automations.java:38-106
The diagram shows the relationship between the Java client, the service layer, and the remote API entities.
Automation Components
An automation is defined by its metadata, its execution logic (steps), and the flow between them (connections).
Workflow Structure
- Steps: Discrete actions within a workflow, such as sending an email, adding a delay, or updating a contact.
- Connections: Logical links that define the transition from one step to another.
- Status: Indicates whether an automation is
ENABLEDorDISABLED.
Sources: src/main/java/com/resend/services/automations/model/Automation.java:11-38, src/main/java/com/resend/services/automations/model/AutomationStep.java:14-25
Step Types
The system supports multiple step types, each managed by specialized builders:
| Step Type | Description | Builder Class |
|---|---|---|
TRIGGER | Initiates the workflow based on an event. | TriggerStepBuilder |
SEND_EMAIL | Sends an email using a template. | SendEmailStepBuilder |
DELAY | Pauses execution for a specified duration. | DelayStepBuilder |
CONTACT_UPDATE | Modifies contact properties. | ContactUpdateStepBuilder |
CONDITION | Branches logic based on criteria. | ConditionStepBuilder |
Sources: src/main/java/com/resend/services/automations/model/AutomationStep.java:62-126, src/main/java/com/resend/services/automations/model/ContactUpdateStepBuilder.java:11-23
Automation Execution and Runs
When an automation is triggered, the system creates an AutomationRun. This object tracks the execution progress and the status of individual steps.
Run Monitoring
You can list runs for a specific automation and filter them by status (e.g., COMPLETED, RUNNING, FAILED). Each run contains a list of AutomationRunStep objects, which include:
- Execution status
- Start and completion timestamps
- Output or error data generated during execution
Sources: src/main/java/com/resend/services/automations/model/AutomationRun.java:11-32, src/main/java/com/resend/services/automations/model/AutomationRunStep.java:11-34
The sequence diagram illustrates the process of retrieving execution details for a specific automation run.
Data Models
List Filtering Parameters
When listing automations or runs, the SDK uses parameter objects to construct query strings.
| Parameter | Type | Description |
|---|---|---|
status | AutomationStatus / RunStatus | Filters results by their current state. |
limit | Integer | Maximum number of items to return. |
after | String | Pagination cursor for the next page. |
before | String | Pagination cursor for the previous page. |
Sources: src/main/java/com/resend/services/automations/model/ListAutomationsParams.java:11-21, src/main/java/com/resend/services/automations/model/ListAutomationRunsParams.java:17-27
Implementation Example: Creating an Automation
You use the builder pattern to define the steps and connections of a workflow.
AutomationStep triggerStep = AutomationStep.trigger("start")
.eventName("user.signup")
.build();
AutomationStep emailStep = AutomationStep.sendEmail("welcome")
.template("welcome-tmpl")
.from("hello@example.com")
.build();
CreateAutomationOptions options = CreateAutomationOptions.builder()
.name("Welcome Workflow")
.steps(triggerStep, emailStep)
.connection(new AutomationConnection("start", "welcome", ConnectionType.DEFAULT))
.build();
Sources: src/test/java/com/resend/services/util/AutomationsUtil.java:15-38, src/main/java/com/resend/services/automations/model/CreateAutomationOptions.java:68-120
Marketing Automations provide a robust framework for event-driven workflows. By combining modular steps with configurable connections, you can automate complex lifecycle marketing tasks directly through the Resend Java SDK.