Skip to content

fix(cloudflare): send reply_to (snake_case) to CF Email Service REST API#12

Open
alisonmwhite wants to merge 1 commit into
0xdps:trunkfrom
alisonmwhite:fix/cf-reply-to-snake-case
Open

fix(cloudflare): send reply_to (snake_case) to CF Email Service REST API#12
alisonmwhite wants to merge 1 commit into
0xdps:trunkfrom
alisonmwhite:fix/cf-reply-to-snake-case

Conversation

@alisonmwhite

Copy link
Copy Markdown

Problem

sendEmail() (both services/backend/src/services/cloudflare.ts and services/worker/src/services/cloudflare.ts) builds the request body with JSON.stringify(params), where params (CFSendEmailParams) carries a camelCase replyTo field.

The Cloudflare Email Service REST API (POST /accounts/{account_id}/email/sending/send) expects snake_case reply_to and validates the body against a strict schema that rejects unknown fields. So any send that sets replyTo fails with:

{"success":false,"errors":[{"code":10001,"message":"email.sending.error.invalid_request_schema"}]}

(HTTP 400). Sends without replyTo succeed 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: true
  • replyTo (camelCase) → 400, email.sending.error.invalid_request_schema

CF docs list the field as reply_to: https://developers.cloudflare.com/email-service/api/send-emails/rest-api/

Fix

Destructure replyTo out of the params and send it as reply_to, omitting when absent. No behavior change when replyTo is unset. Applied to both the backend and worker sendEmail implementations.

…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>
Copilot AI review requested due to automatic review settings June 4, 2026 01:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 replyToreply_to and 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 } : {}) };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants