Skip to content

fix(emails): send transactional emails through /api/messaging - #256

Merged
rafaeelaudibert merged 2 commits into
mainfrom
rafa/emails-key-scoped-api
Nov 18, 2026
Merged

rafaeelaudibert merged 2 commits into
mainfrom
rafa/emails-key-scoped-api

Conversation

@rafaeelaudibert

Copy link
Copy Markdown
Member

💡 Motivation and Context

PostHog.Emails calls /api/projects/@current/messaging/.... PostHog is removing the @current project alias, so these calls will stop working.

PostHog/posthog#137605 added key-scoped routes that take the project from the project secret API key. This PR moves the SDK to them:

Before After
/api/projects/@current/messaging/send/email/ /api/messaging/send/email/
/api/projects/@current/messaging/attachments/uploads/ /api/messaging/attachments/uploads/
/api/projects/@current/messaging/emails/{id}/ /api/messaging/emails/{id}/

This is an outright switch with no fallback. PostHog instances older than PostHog/posthog#137605 answer 404. US and EU Cloud already serve the new routes.

💚 How did you test it?

  • mix test test/posthog/emails_test.exs test/posthog/emails_default_instance_test.exs: 118 tests, 0 failures. Run on Elixir 1.18.3 / OTP 27, because the .tool-versions pins (1.20.0 / OTP 29) are not installed locally.
  • mix format --check-formatted and mix credo --strict lib/posthog/emails.ex pass.
  • Not tested against a live PostHog instance.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran sampo add to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Written by Claude Code (Claude Opus 5.5, claude-opus-5-5).
  • Only the three messaging paths the SDK calls changed. The SDK makes no other @current calls and does not call the preferences route.
  • Added a hand-written patch changeset in .sampo/changesets/, because the sampo CLI was not installed.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rafaeelaudibert
rafaeelaudibert requested a review from a team as a code owner November 18, 2026 02:30
@rafaeelaudibert rafaeelaudibert self-assigned this Nov 18, 2026
@veria-ai

veria-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

PR overview

No security issues were found in this pull request.

Reviews

@posthog posthog Bot 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.

PostHog Review · Standard · reviewed c85d434: 1 Should fix.

See this review and its findings in PostHog Review. Comment @posthog review --deep for a Deep review. A Deep review takes longer and looks deeper than a Standard review.

Comment thread lib/posthog/emails.ex
Comment on lines +182 to +184
@send_path "/api/messaging/send/email/"
@uploads_path "/api/messaging/attachments/uploads/"
@status_path "/api/messaging/emails/"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 · Preserve older-server compatibility in the patch release

On self-hosted PostHog versions predating the new routes, these constants make every email send, attachment upload and status read return 404 despite valid credentials. Existing app_host configurations therefore stop working after the patch upgrade declared by this PR. Preserve a compatible routing option or ship this compatibility removal as a breaking release.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not acting on this one on purpose: the SDKs switch to the key-scoped routes outright, with no fallback to the project path. The routes are live on PostHog Cloud (PostHog/posthog#137605), and keeping the old path would keep the SDKs on the @current alias that this change exists to retire.

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

posthog-elixir Compliance Report

Date: 2026-11-18T17:42:00.507291+00:00
Duration: 111131ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 608ms
Format Validation.Event Has Uuid ✅ 609ms
Format Validation.Event Has Lib Properties ✅ 609ms
Format Validation.Distinct Id Is String ✅ 609ms
Format Validation.Token Is Present ✅ 609ms
Format Validation.Custom Properties Preserved ✅ 609ms
Format Validation.Event Has Timestamp ✅ 609ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 609ms
Retry Behavior.Retries On 503 ✅ 5613ms
Retry Behavior.Does Not Retry On 400 ✅ 2610ms
Retry Behavior.Does Not Retry On 401 ✅ 2611ms
Retry Behavior.Respects Retry After Header ✅ 5615ms
Retry Behavior.Implements Backoff ✅ 15624ms
Retry Behavior.Retries On 500 ✅ 5614ms
Retry Behavior.Retries On 502 ✅ 5614ms
Retry Behavior.Retries On 504 ✅ 5615ms
Retry Behavior.Max Retries Respected ✅ 15620ms
Deduplication.Generates Unique Uuids ✅ 617ms
Deduplication.Preserves Uuid On Retry ✅ 5613ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10619ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5616ms
Deduplication.No Duplicate Events In Batch ✅ 614ms
Deduplication.Different Events Have Different Uuids ✅ 610ms
Compression.Sends Gzip When Enabled ✅ 608ms
Batch Format.Uses Proper Batch Structure ✅ 609ms
Batch Format.Flush With No Events Sends Nothing ✅ 606ms
Batch Format.Multiple Events Batched Together ✅ 612ms
Error Handling.Does Not Retry On 403 ✅ 2611ms
Error Handling.Does Not Retry On 413 ✅ 2611ms
Error Handling.Retries On 408 ✅ 5614ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 9ms
Request Payload.Flags Request Uses V2 Query Param ✅ 5ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 6ms
Request Payload.Flags Request Omits Authorization Header ✅ 5ms
Request Payload.Token In Flags Body Matches Init ✅ 5ms
Request Payload.Groups Round Trip ✅ 6ms
Request Payload.Groups Default To Empty Object ✅ 5ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 5ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 6ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 5ms
Request Lifecycle.No Flags Request On Init Alone ✅ 3ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 607ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 11ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 606ms
Retry Behavior.Retries Flags On 502 ✅ 911ms
Retry Behavior.Retries Flags On 504 ✅ 911ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 1212ms

hex/posthog: patch
---

`PostHog.Emails` now sends emails, uploads attachments and reads email status through `/api/messaging/`, which takes the project from the project secret API key, instead of `/api/projects/@current/messaging/`. PostHog instances older than these routes answer 404.

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.

Note

🤖 Claude Opus 5.5 responding on behalf of Michael

One ask on the changeset: could it name the server this needs? Something like "Needs PostHog Cloud, or a self-hosted build from 2026-11-18 or later; older self-hosted builds answer these calls with 404." I'd keep the patch bump: Cloud users see no change, and a major costs every user an upgrade for a self-hosted edge case.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added in 5d53f26: "Needs PostHog Cloud, or a self-hosted PostHog from 2026-11-18 or later. Older self-hosted versions answer these calls with a 404." Kept the patch bump.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rafaeelaudibert
rafaeelaudibert merged commit 8516142 into main Nov 18, 2026
30 checks passed
@rafaeelaudibert
rafaeelaudibert deleted the rafa/emails-key-scoped-api branch November 18, 2026 18:22
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.

2 participants