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/easy-toys-deny.md
Original file line number Diff line number Diff line change
@@ -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/`. 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/Emails.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/';
Comment on lines +44 to +46

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.

P2 · Preserve compatibility with instances that lack the new routes

On self-hosted instances predating the new backend routes, upgrading this SDK makes previously working send() and get() calls fail with HTTP 404, including attachment uploads. These constants switch every request unconditionally, so the patch release breaks existing integrations without any application change. Retain a fallback for servers lacking the new routes.

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.

private const US_APP_HOST = 'https://us.posthog.com';
private const EU_APP_HOST = 'https://eu.posthog.com';
private const CLOUD_APP_HOSTS = [
Expand Down
6 changes: 3 additions & 3 deletions test/EmailsClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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)]]],
],
Expand Down Expand Up @@ -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/ ')
);
}

Expand Down
8 changes: 4 additions & 4 deletions test/EmailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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']);
Expand Down
Loading