Automations API
Relevant source files
The following files were used as context for generating this wiki page:
The Automations API provides tools to automate email sequences and workflows based on specific triggers and conditions. It allows you to programmatically create, manage, and monitor complex marketing or transactional flows within the Resend ecosystem.
This module interfaces with the /automations endpoints to handle the lifecycle of an automation, including its definition through steps and connections, and the tracking of individual automation runs. It integrates closely with other services such as Templates for email content and Events for triggering workflows.
Sources: src/automations.rs:1-20, src/lib.rs:100-115
Service Architecture
The AutomationsSvc struct acts as the primary entry point for automation operations. It holds an Arc<Config> to manage API authentication and request building.
The diagram shows the relationship between the service handler and the core data model.
Sources: src/automations.rs:20-130, src/automations.rs:264-272
Workflow Components
An automation consists of two primary structural elements: Steps and Connections.
Steps
Steps represent individual actions or logic gates within the workflow. Each step requires a unique key and a specific configuration based on its type.
| Step Type | Description | Config Payload |
|---|---|---|
Trigger | Initiates the automation based on a named event. | TriggerStepConfig |
SendEmail | Dispatches an email using a specified template. | SendEmailStepConfig |
Delay | Pauses the workflow for a specific duration. | DelayStepConfig |
WaitForEvent | Halts execution until a specific event occurs or a timeout is reached. | WaitForEventStepConfig |
Condition | Branches logic based on defined criteria. | serde_json::Value |
AddToSegment | Subscribes the contact to a specific segment. | AddToSegmentStepConfig |
Sources: src/automations.rs:161-193, src/automations.rs:228-231
Connections
Connections define the flow of execution between steps. They link a source step (from) to a destination step (to).
The diagram illustrates how connections move the automation run through various logic states.
Sources: src/automations.rs:242-261
Automation Management
You can control the state and lifecycle of automations through the following operations:
- Creation: Define the name, status, steps, and connections to initialize a workflow.
- Lifecycle Control: Use
stop()to halt active processes orduplicate()to clone an existing configuration for testing or iteration. - Updates: Modify the
AutomationStatus(Enabled/Disabled) or restructure the workflow by providing new steps and connections. - Monitoring: Retrieve lists of
AutomationRunobjects to audit execution history and trigger payloads.
Sources: src/automations.rs:27-128, src/automations.rs:309-317
Status Tracking
The system tracks the status of both the automation definition and its individual executions (runs).
| Object | Status Options |
|---|---|
| Automation | Enabled, Disabled |
| AutomationRun | Running, Completed, Failed, Cancelled |
Sources: src/automations.rs:152-159, src/automations.rs:319-325
Integration with Events and Templates
Automations rely on the broader Resend infrastructure for execution:
- Events: Named events (e.g., "user.created") serve as triggers for the
Triggerstep. You can send these via theEventsSvc. Sources: src/events.rs:50-57 - Templates: The
SendEmailstep references aTemplateId. TheAutomationTemplatestructure allows passing variables to these templates during execution. Sources: src/automations.rs:212-225, src/templates.rs:141-155 - Segments: Steps like
AddToSegmentinteract with the contact management system to organize recipients. Sources: src/contacts.rs:172-185
Usage and Quotas
Automation execution is subject to account-level quotas. The AutomationRunsUsage struct tracks the number of runs used against the maximum allowed limit for the current billing period.
Sources: src/usage.rs:113-121
The Automations API enables the construction of resilient, event-driven communication workflows by combining flexible step definitions with robust status tracking and run monitoring.