Broadcasts API
Relevant source files
The following files were used as context for generating this wiki page:
The Broadcasts API enables users to create, manage, and send bulk email communications to specific audiences. It provides a structured interface for managing the lifecycle of a broadcast, from initial draft creation to delivery and performance tracking.
Users interact with this system through the BroadcastsSvc service, which handles requests to the /broadcasts endpoints. This API supports advanced operations such as scheduling, cancellation, duplication, and detailed recipient event tracking.
Sources: src/broadcasts.rs:18-20, src/lib.rs:89-91
Service Architecture
The BroadcastsSvc struct manages API interactions by wrapping an Arc<Config>. It uses the internal Config to build and send HTTP requests using the reqwest library.
The diagram shows the flow of data from the client service through the request builder to the Resend API.
Sources: src/broadcasts.rs:18-150, src/config.rs:141-160
Broadcast Lifecycle Management
A broadcast moves through several states including draft, scheduled, and sent. The API provides specific methods to control these transitions.
Core Operations
| Method | Description | Endpoint |
|---|---|---|
create | Creates a new broadcast draft for an audience. | POST /broadcasts |
send | Triggers the sending process for a broadcast. | POST /broadcasts/{id}/send |
get | Retrieves details of a specific broadcast. | GET /broadcasts/{id} |
update | Modifies an existing broadcast draft. | PATCH /broadcasts/{id} |
cancel | Cancels a scheduled broadcast. | POST /broadcasts/{id}/cancel |
duplicate | Creates a new draft based on an existing broadcast. | POST /broadcasts/{id}/duplicate |
delete | Removes a broadcast from the system. | DELETE /broadcasts/{id} |
Sources: src/broadcasts.rs:24-118, CHANGELOG.md:46-51
Creation and Configuration
The CreateBroadcastOptions struct configures new broadcasts. It requires an audience_id, from address, and subject. Users can optionally include HTML content, plain text, and scheduled send times.
This sequence illustrates the creation of a broadcast resource.
Sources: src/broadcasts.rs:155-234
Performance Tracking and Analytics
The API provides granular data on how recipients interact with a broadcast. This includes tracking link clicks and specific delivery events.
Recipient Events
The recipients method retrieves list of recipients filtered by BroadcastRecipientEventType. Events include Opened, Clicked, Bounced, and Unsubscribed.
The ER diagram shows the relationship between a broadcast, its recipients, and the links they interact with.
Sources: src/broadcasts.rs:139-150, src/broadcasts.rs:434-453
Link Tracking
The clicked_links method returns a ranked list of URLs clicked within a broadcast. The BroadcastClickedLink struct provides both total clicks and unique_clicks.
Sources: src/broadcasts.rs:103-118, src/broadcasts.rs:468-477
Usage and Quotas
Broadcast activity is monitored at the account level. The UsageSvc provides data on broadcast consumption.
| Field | Type | Description |
|---|---|---|
used | u32 | Total number of broadcasts sent. |
limit | Option<u32> | Maximum allowed broadcasts (typically unlimited). |
Sources: src/usage.rs:36-105
Data Structures
Broadcast Model
The primary Broadcast struct contains the state and content of the communication.
pub struct Broadcast {
pub id: BroadcastId,
pub name: String,
pub audience_id: SegmentId,
pub status: String,
pub created_at: String,
pub scheduled_at: Option<String>,
pub sent_at: Option<String>,
pub from: Option<String>,
pub subject: Option<String>,
pub reply_to: Option<Vec<String>>,
pub preview_text: Option<String>,
pub text: Option<String>,
pub html: Option<String>,
}
Sources: src/broadcasts.rs:356-370
The Broadcasts API integrates with the project's audience management to deliver targeted content. By providing both management and analytical endpoints, it allows developers to build robust email marketing workflows within the Resend ecosystem.