Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/emails-key-scoped-api.md
Original file line number Diff line number Diff line change
@@ -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. Needs PostHog Cloud, or a self-hosted PostHog from 2026-11-18 or later. Older self-hosted versions answer these calls with a 404.
6 changes: 3 additions & 3 deletions lib/posthog/emails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/%<message_id>s/'
SEND_PATH = '/api/messaging/send/email/'
UPLOADS_PATH = '/api/messaging/attachments/uploads/'
STATUS_PATH = '/api/messaging/emails/%<message_id>s/'
US_APP_HOST = 'https://us.posthog.com'
EU_APP_HOST = 'https://eu.posthog.com'
CLOUD_APP_HOSTS = {
Expand Down
10 changes: 5 additions & 5 deletions spec/posthog/emails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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) }
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading