fix(cloudflare): send reply_to (snake_case) to CF Email Service REST API#12
Open
alisonmwhite wants to merge 1 commit into
Open
fix(cloudflare): send reply_to (snake_case) to CF Email Service REST API#12alisonmwhite wants to merge 1 commit into
alisonmwhite wants to merge 1 commit into
Conversation
…T API sendEmail() (both backend and worker variants) built the request body with JSON.stringify(params), where params carries a camelCase `replyTo`. The Cloudflare Email Service REST API expects snake_case `reply_to` and validates against a strict schema that rejects unknown fields, so any send with replyTo set failed with email.sending.error.invalid_request_schema (HTTP 400). Sends without replyTo succeeded because the field was simply absent, which made the bug easy to miss. Map replyTo -> reply_to and omit when absent. Verified against the CF API: identical body with reply_to -> 200, replyTo -> 400. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates Cloudflare Email Service requests to map the client-facing replyTo (camelCase) field to Cloudflare’s expected reply_to (snake_case), avoiding Cloudflare’s strict-schema rejection.
Changes:
- Map
replyTo→reply_toand omit the field when absent. - Apply the same request-body transformation in both worker and backend Cloudflare email senders.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| services/worker/src/services/cloudflare.ts | Builds a Cloudflare-compatible email request body by remapping replyTo to reply_to. |
| services/backend/src/services/cloudflare.ts | Mirrors the same remapping logic for backend Cloudflare email requests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+200
to
+204
| // The Cloudflare Email Service REST API expects snake_case `reply_to`; our | ||
| // params use camelCase `replyTo`. Map it (and omit when absent) — CF's schema | ||
| // is strict and rejects unknown fields with invalid_request_schema. | ||
| const { replyTo, ...rest } = params; | ||
| const body = { ...rest, ...(replyTo ? { reply_to: replyTo } : {}) }; |
Comment on lines
+169
to
+173
| // The Cloudflare Email Service REST API expects snake_case `reply_to`; our | ||
| // params use camelCase `replyTo`. Map it (and omit when absent) — CF's schema | ||
| // is strict and rejects unknown fields with invalid_request_schema. | ||
| const { replyTo, ...rest } = params; | ||
| const body = { ...rest, ...(replyTo ? { reply_to: replyTo } : {}) }; |
Comment on lines
+172
to
+173
| const { replyTo, ...rest } = params; | ||
| const body = { ...rest, ...(replyTo ? { reply_to: replyTo } : {}) }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
sendEmail()(bothservices/backend/src/services/cloudflare.tsandservices/worker/src/services/cloudflare.ts) builds the request body withJSON.stringify(params), whereparams(CFSendEmailParams) carries a camelCasereplyTofield.The Cloudflare Email Service REST API (
POST /accounts/{account_id}/email/sending/send) expects snake_casereply_toand validates the body against a strict schema that rejects unknown fields. So any send that setsreplyTofails with:{"success":false,"errors":[{"code":10001,"message":"email.sending.error.invalid_request_schema"}]}(HTTP 400). Sends without
replyTosucceed because the unknown field is simply absent — which makes this easy to miss until a Reply-To is actually needed.Verification
Direct CF API call, identical body otherwise:
reply_to(snake_case) →200,success: truereplyTo(camelCase) →400,email.sending.error.invalid_request_schemaCF docs list the field as
reply_to: https://developers.cloudflare.com/email-service/api/send-emails/rest-api/Fix
Destructure
replyToout of the params and send it asreply_to, omitting when absent. No behavior change whenreplyTois unset. Applied to both the backend and workersendEmailimplementations.