From 32162b5f0a03a4b576d715d3f869eee41e915a2f Mon Sep 17 00:00:00 2001 From: Rafa Audibert Date: Tue, 17 Nov 2026 23:28:37 -0300 Subject: [PATCH 1/2] fix(emails): send transactional emails through /api/messaging The SDK called the transactional email routes under /api/projects/@current/, and the @current alias is being removed. PostHog now serves key-scoped routes that take the project from the project secret API key, so send, attachment upload and status requests go to /api/messaging/ instead. Co-Authored-By: Claude Opus 5.5 --- .changeset/easy-toys-deny.md | 5 +++++ lib/Emails.php | 6 +++--- test/EmailsClientTest.php | 6 +++--- test/EmailsTest.php | 8 ++++---- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 .changeset/easy-toys-deny.md diff --git a/.changeset/easy-toys-deny.md b/.changeset/easy-toys-deny.md new file mode 100644 index 0000000..c3d4869 --- /dev/null +++ b/.changeset/easy-toys-deny.md @@ -0,0 +1,5 @@ +--- +"posthog-php": patch +--- + +Transactional email: send, attachment upload and status requests now use the key-scoped `/api/messaging/` routes instead of `/api/projects/@current/messaging/`. They need a PostHog version with those routes; an older self-hosted instance answers 404. diff --git a/lib/Emails.php b/lib/Emails.php index 7ebd887..19015b0 100644 --- a/lib/Emails.php +++ b/lib/Emails.php @@ -41,9 +41,9 @@ final class Emails public const DEFAULT_REQUEST_TIMEOUT_MS = 15000; public const DEFAULT_MAX_RETRIES = 2; - private const SEND_PATH = '/api/projects/@current/messaging/send/email/'; - private const UPLOADS_PATH = '/api/projects/@current/messaging/attachments/uploads/'; - private const STATUS_PATH = '/api/projects/@current/messaging/emails/%s/'; + private const SEND_PATH = '/api/messaging/send/email/'; + private const UPLOADS_PATH = '/api/messaging/attachments/uploads/'; + private const STATUS_PATH = '/api/messaging/emails/%s/'; private const US_APP_HOST = 'https://us.posthog.com'; private const EU_APP_HOST = 'https://eu.posthog.com'; private const CLOUD_APP_HOSTS = [ diff --git a/test/EmailsClientTest.php b/test/EmailsClientTest.php index 9669bb2..079b96b 100644 --- a/test/EmailsClientTest.php +++ b/test/EmailsClientTest.php @@ -56,7 +56,7 @@ public function testACodeSendReachesTheSendRouteOverHttp(): void $this->assertSame('01a18356-c56c-0001-e494-7666bc915188', $result->getId()); $requests = $this->server->requests(); $this->assertCount(1, $requests); - $this->assertSame('POST /api/projects/@current/messaging/send/email/ HTTP/1.1', $requests[0]['requestLine']); + $this->assertSame('POST /api/messaging/send/email/ HTTP/1.1', $requests[0]['requestLine']); $headers = $requests[0]['headers']; $this->assertSame('Bearer phs_secret', $headers['authorization']); $this->assertSame('application/json', $headers['content-type']); @@ -105,7 +105,7 @@ public function testAFileIsUploadedWithAPlainPutBeforeTheSendOverHttp(): void 'url_expires_at' => '2026-11-02T12:15:00Z', ]]]), 'accepts' => [ - 'request_line' => 'POST /api/projects/@current/messaging/attachments/uploads/ HTTP/1.1', + 'request_line' => 'POST /api/messaging/attachments/uploads/ HTTP/1.1', 'authorization' => 'Bearer phs_secret', 'json_body' => ['files' => [['sha256' => $sha256, 'size' => strlen($file)]]], ], @@ -144,7 +144,7 @@ private function queuedEmails(): array { return array_map( static fn(array $send): array => json_decode($send['body'], true), - self::accepted($this->server, 'POST /api/projects/@current/messaging/send/email/ ') + self::accepted($this->server, 'POST /api/messaging/send/email/ ') ); } diff --git a/test/EmailsTest.php b/test/EmailsTest.php index 07f4cee..a8040c1 100644 --- a/test/EmailsTest.php +++ b/test/EmailsTest.php @@ -16,7 +16,7 @@ class EmailsTest extends TestCase { private const TEMPLATE_ID = '0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b'; private const MESSAGE_ID = '01a18356-c56c-0001-e494-7666bc915188'; - private const SEND_URL = 'https://us.posthog.com/api/projects/@current/messaging/send/email/'; + private const SEND_URL = 'https://us.posthog.com/api/messaging/send/email/'; private const INVITE = "BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n"; private const SECRET_CONTENT = 'secret-file-content'; @@ -416,7 +416,7 @@ public function testNullOptionsAndAnEmptyReplyToCountAsLeftOut(): void ], $this->body()); } - private const UPLOAD_URL = 'https://us.posthog.com/api/projects/@current/messaging/attachments/uploads/'; + private const UPLOAD_URL = 'https://us.posthog.com/api/messaging/attachments/uploads/'; private const INVITE_SHA256 = '215efae54e34ac5657da47b49c8d1bd8ea12649ee1efa838c9a47d7233f18afb'; private const PNG = "\x89PNG\r\n\x1a\n\x00"; private const PNG_SHA256 = '843ac23b1736b4487ec81cf7c07ddd9bb46ae5b7818c2c3843d99d62fa75f3c9'; @@ -1246,7 +1246,7 @@ public function testRequestsGoToTheAppHost(string $host, ?string $appHost, strin $this->emails(['host' => $host, 'appHost' => $appHost]) ->send(['to' => 'user@example.com', 'template_id' => self::TEMPLATE_ID]); - $this->assertSame($expected . '/api/projects/@current/messaging/send/email/', $this->requests[0]['url']); + $this->assertSame($expected . '/api/messaging/send/email/', $this->requests[0]['url']); } public static function responseErrors(): array @@ -1527,7 +1527,7 @@ public function testGetReadsTheStatus(): void $this->assertSame('GET', $this->requests[0]['method']); $this->assertSame( - 'https://us.posthog.com/api/projects/@current/messaging/emails/' . self::MESSAGE_ID . '/', + 'https://us.posthog.com/api/messaging/emails/' . self::MESSAGE_ID . '/', $this->requests[0]['url'] ); $this->assertNull($this->requests[0]['body']); From 793a02ae57762f037c75c9a2a3895f02e5703b90 Mon Sep 17 00:00:00 2001 From: Rafa Audibert Date: Wed, 18 Nov 2026 14:38:26 -0300 Subject: [PATCH 2/2] chore(emails): name the server version the key-scoped routes need Co-Authored-By: Claude Opus 5.5 --- .changeset/easy-toys-deny.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/easy-toys-deny.md b/.changeset/easy-toys-deny.md index c3d4869..0f501fe 100644 --- a/.changeset/easy-toys-deny.md +++ b/.changeset/easy-toys-deny.md @@ -2,4 +2,4 @@ "posthog-php": patch --- -Transactional email: send, attachment upload and status requests now use the key-scoped `/api/messaging/` routes instead of `/api/projects/@current/messaging/`. They need a PostHog version with those routes; an older self-hosted instance answers 404. +Transactional email: send, attachment upload and status requests now use the key-scoped `/api/messaging/` routes instead of `/api/projects/@current/messaging/`. Needs PostHog Cloud, or a self-hosted PostHog from 2026-11-18 or later. Older self-hosted versions answer these calls with a 404.