Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/resend/batch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ module Batch
class << self
# Send a batch of emails
#
# @param params [Array<Hash>] Array of email parameters (max 100 emails)
# Each email in +params+ accepts the same fields as {Resend::Emails.send},
# including +tags+ per email.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The docstring says "Each hash accepts the same fields as {Resend::Emails.send}, including:" but according to the Resend API docs, attachments and scheduled_at are explicitly not supported on the batch endpoint (POST /emails/batch). Saying "same fields" without the exception is misleading — users who read this will pass attachments or scheduled_at parameters and silently fail or get an error at runtime. The previous version (before this PR) had no field-level documentation, which was incomplete but not actively misleading. Recommend restoring the caveat that attachments and scheduled_at are not supported in batch, e.g. "Each hash accepts the same fields as {Resend::Emails.send}, including +tags+ per email, except +scheduled_at+ and +attachments+ which are not supported in batch."

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At lib/resend/batch.rb, line 10:

<comment>The docstring says "Each hash accepts the same fields as {Resend::Emails.send}, including:" but according to the Resend API docs, `attachments` and `scheduled_at` are explicitly **not supported** on the batch endpoint (`POST /emails/batch`). Saying "same fields" without the exception is misleading — users who read this will pass `attachments` or `scheduled_at` parameters and silently fail or get an error at runtime. The previous version (before this PR) had no field-level documentation, which was incomplete but not actively misleading. Recommend restoring the caveat that `attachments` and `scheduled_at` are not supported in batch, e.g. "Each hash accepts the same fields as {Resend::Emails.send}, including +tags+ per email, except +scheduled_at+ and +attachments+ which are not supported in batch."</comment>

<file context>
@@ -7,11 +7,10 @@ class << self
       # Each email in +params+ accepts the same fields as {Resend::Emails.send},
-      # except +scheduled_at+ and +attachments+, which are not supported in batch.
-      # +tags+ are supported per email.
+      # including +tags+ per email.
       #
       # @param params [Array<Hash>] Array of email parameters (max 100 emails).
</file context>

#
# @param params [Array<Hash>] Array of email parameters (max 100 emails).
# Each hash accepts the same fields as {Resend::Emails.send}, including:
# - +tags+ [Array<Hash>] Key/value tags, e.g. [{ name: "category", value: "welcome" }]
# @param options [Hash] Additional options for the request
# @option options [String] :idempotency_key Optional idempotency key
# @option options [String] :batch_validation Batch validation mode: "strict" (default) or "permissive"
Expand Down
39 changes: 39 additions & 0 deletions spec/batch_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,45 @@
expect(result[:errors][0][:message]).to include("valid email address")
end

it "passes tags in the request body" do
resp = {
"data": [
{ "id": "ae2014de-c168-4c61-8267-70d2662a1ce1" }
]
}

params = [
{
from: "from@e.io",
to: ["email1@email.com"],
subject: "Tagged email",
html: "<p>Hello</p>",
tags: [
{ name: "category", value: "welcome" }
]
}
]

allow(resp).to receive(:body).and_return(resp)
allow(HTTParty).to receive(:send).and_return(resp)

Resend::Batch.send(params)

expect(HTTParty).to have_received(:send).with(
:post,
"#{Resend::Request::BASE_URL}emails/batch",
{
headers: {
"Content-Type" => "application/json",
"Accept" => "application/json",
"Authorization" => "Bearer re_123",
"User-Agent" => "resend-ruby:#{Resend::VERSION}",
},
body: params.to_json
}
)
end

it "sends batch email with templates" do
resp = {
"data": [
Expand Down