From 2f71272d67e30896d3d724d5efe2f5395bf7d456 Mon Sep 17 00:00:00 2001 From: Rafa Audibert Date: Tue, 17 Nov 2026 23:25:38 -0300 Subject: [PATCH 1/2] fix(emails): send transactional emails through /api/messaging Co-Authored-By: Claude Opus 5.5 --- .changeset/emails-key-scoped-api.md | 5 +++++ lib/posthog/emails.rb | 6 +++--- spec/posthog/emails_spec.rb | 10 +++++----- 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 .changeset/emails-key-scoped-api.md diff --git a/.changeset/emails-key-scoped-api.md b/.changeset/emails-key-scoped-api.md new file mode 100644 index 00000000..eef47b55 --- /dev/null +++ b/.changeset/emails-key-scoped-api.md @@ -0,0 +1,5 @@ +--- +"posthog-ruby": patch +--- + +Send transactional emails, attachment uploads, and email status requests through `/api/messaging/` instead of the `/api/projects/@current/messaging/` alias. PostHog instances without these routes answer 404. diff --git a/lib/posthog/emails.rb b/lib/posthog/emails.rb index de77249c..52f3b387 100644 --- a/lib/posthog/emails.rb +++ b/lib/posthog/emails.rb @@ -71,9 +71,9 @@ class Emails # of a bounced email: `hard`, `soft` or `unknown`. Status = Struct.new(:id, :status, :created_at, :status_at, :reason, keyword_init: true) - SEND_PATH = '/api/projects/@current/messaging/send/email/' - UPLOADS_PATH = '/api/projects/@current/messaging/attachments/uploads/' - STATUS_PATH = '/api/projects/@current/messaging/emails/%s/' + SEND_PATH = '/api/messaging/send/email/' + UPLOADS_PATH = '/api/messaging/attachments/uploads/' + STATUS_PATH = '/api/messaging/emails/%s/' US_APP_HOST = 'https://us.posthog.com' EU_APP_HOST = 'https://eu.posthog.com' CLOUD_APP_HOSTS = { diff --git a/spec/posthog/emails_spec.rb b/spec/posthog/emails_spec.rb index 5fd3bfda..c371c6ff 100644 --- a/spec/posthog/emails_spec.rb +++ b/spec/posthog/emails_spec.rb @@ -5,10 +5,10 @@ module PostHog describe Emails do - let(:send_url) { 'https://us.posthog.com/api/projects/@current/messaging/send/email/' } + let(:send_url) { 'https://us.posthog.com/api/messaging/send/email/' } let(:template_id) { '0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b' } let(:message_id) { '01a18356-c56c-0001-e494-7666bc915188' } - let(:status_url) { "https://us.posthog.com/api/projects/@current/messaging/emails/#{message_id}/" } + let(:status_url) { "https://us.posthog.com/api/messaging/emails/#{message_id}/" } let(:uuid_v4) { /\A\h{8}-\h{4}-4\h{3}-[89ab]\h{3}-\h{12}\z/ } let(:options) { { api_key: API_KEY, secret_key: ' phs_test ', test_mode: true } } let(:client) { Client.new(options) } @@ -258,7 +258,7 @@ def send_code(**overrides) before { fake_posthog } def fake_posthog(app: 'https://us.posthog.com', storage: 'https://files.example.com/team') - routes = "#{app}/api/projects/@current/messaging" + routes = "#{app}/api/messaging" stub_request(:post, "#{routes}/attachments/uploads/").to_return { |request| plan_uploads(request, storage) } stub_request(:put, %r{/team/\h{64}\?}).to_return { |request| store(request) } stub_request(:post, "#{routes}/send/email/").to_return { |request| accept_send(request) } @@ -801,7 +801,7 @@ def refused_attachment(**overrides) describe 'client setup' do it 'maps an EU ingestion host to the EU app host' do options[:host] = 'https://eu.i.posthog.com/' - stub_request(:post, 'https://eu.posthog.com/api/projects/@current/messaging/send/email/').to_return(accept) + stub_request(:post, 'https://eu.posthog.com/api/messaging/send/email/').to_return(accept) expect(send_template.id).to eq('msg_1') end @@ -818,7 +818,7 @@ def refused_attachment(**overrides) it 'sends to app_host when the client sets it' do options.merge!(host: 'https://proxy.example.com', app_host: 'https://posthog.example.com/') - stub_request(:post, 'https://posthog.example.com/api/projects/@current/messaging/send/email/').to_return(accept) + stub_request(:post, 'https://posthog.example.com/api/messaging/send/email/').to_return(accept) expect(send_template.id).to eq('msg_1') end From 2ae0da2522dc735d89ee7951f6a2bc9e812c328a Mon Sep 17 00:00:00 2001 From: Rafa Audibert Date: Wed, 18 Nov 2026 14:38:30 -0300 Subject: [PATCH 2/2] chore(emails): name the server version the key-scoped routes need Co-Authored-By: Claude Opus 5.5 --- .changeset/emails-key-scoped-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/emails-key-scoped-api.md b/.changeset/emails-key-scoped-api.md index eef47b55..8d80370d 100644 --- a/.changeset/emails-key-scoped-api.md +++ b/.changeset/emails-key-scoped-api.md @@ -2,4 +2,4 @@ "posthog-ruby": patch --- -Send transactional emails, attachment uploads, and email status requests through `/api/messaging/` instead of the `/api/projects/@current/messaging/` alias. PostHog instances without these routes answer 404. +Send transactional emails, attachment uploads, and email status requests through `/api/messaging/` instead of the `/api/projects/@current/messaging/` alias. Needs PostHog Cloud, or a self-hosted PostHog from 2026-11-18 or later. Older self-hosted versions answer these calls with a 404.