From 3761473cc05c0927aab78a8fdc2451fcaecbe583 Mon Sep 17 00:00:00 2001 From: Rafa Audibert Date: Tue, 17 Nov 2026 23:30:56 -0300 Subject: [PATCH 1/2] fix(emails): send transactional emails through /api/messaging PostHog is removing the @current project alias. Send emails, upload attachments and read email statuses through the key-scoped /api/messaging/ routes, which take the project from the project secret API key. Co-Authored-By: Claude Opus 5.5 --- .sampo/changesets/emails-key-scoped-api.md | 5 +++++ posthog/emails.py | 6 +++--- posthog/test/test_emails.py | 10 ++++------ 3 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 .sampo/changesets/emails-key-scoped-api.md diff --git a/.sampo/changesets/emails-key-scoped-api.md b/.sampo/changesets/emails-key-scoped-api.md new file mode 100644 index 000000000..85c3cb124 --- /dev/null +++ b/.sampo/changesets/emails-key-scoped-api.md @@ -0,0 +1,5 @@ +--- +pypi/posthog: patch +--- + +`posthog.emails` sends emails, uploads attachments and reads email statuses through `/api/messaging/...`, which takes the project from the project secret API key. It no longer calls `/api/projects/@current/messaging/...`, since PostHog is removing the `@current` alias. A self-hosted PostHog older than these routes answers these calls with 404. diff --git a/posthog/emails.py b/posthog/emails.py index 1f0bfaec4..c180a9224 100644 --- a/posthog/emails.py +++ b/posthog/emails.py @@ -179,9 +179,9 @@ log = logging.getLogger("posthog") -_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}/" +_SEND_PATH = "/api/messaging/send/email/" +_UPLOADS_PATH = "/api/messaging/attachments/uploads/" +_STATUS_PATH = "/api/messaging/emails/{message_id}/" _TEMPLATE_KEY = re.compile(r"[a-zA-Z0-9_-]{1,400}") _MAX_RETRY_DELAY = 30.0 _IDEMPOTENCY_KEY = re.compile(r"^[\x21-\x7e]{1,255}$") diff --git a/posthog/test/test_emails.py b/posthog/test/test_emails.py index b2690cff0..9e1a15db6 100644 --- a/posthog/test/test_emails.py +++ b/posthog/test/test_emails.py @@ -35,11 +35,9 @@ SECRET_KEY = "phs_test_secret" TEMPLATE_ID = "0190f6d2-7c1e-7b3a-9f5e-1c2d3e4f5a6b" -SEND_URL = "https://us.posthog.com/api/projects/@current/messaging/send/email/" +SEND_URL = "https://us.posthog.com/api/messaging/send/email/" MESSAGE_ID = "01a18356-c56c-0001-e494-7666bc915188" -STATUS_URL = ( - f"https://us.posthog.com/api/projects/@current/messaging/emails/{MESSAGE_ID}/" -) +STATUS_URL = f"https://us.posthog.com/api/messaging/emails/{MESSAGE_ID}/" Reply = Union[Exception, tuple[int, Optional[dict[str, Any]], dict[str, str]]] @@ -1058,8 +1056,8 @@ def test_a_refused_send_names_the_field_from_attr(): POSTHOG_HOST = "https://us.posthog.com" -UPLOADS_PATH = "/api/projects/@current/messaging/attachments/uploads/" -SEND_PATH = "/api/projects/@current/messaging/send/email/" +UPLOADS_PATH = "/api/messaging/attachments/uploads/" +SEND_PATH = "/api/messaging/send/email/" STORAGE_URL = "https://files.example.com/team/1" STORAGE_SIGNING_KEY = b"fake-storage-signing-key" URL_LIFETIME_SECONDS = 900 From 354c4a710083e837a98388c284be7392bd8f0683 Mon Sep 17 00:00:00 2001 From: Rafa Audibert Date: Wed, 18 Nov 2026 14:38:19 -0300 Subject: [PATCH 2/2] chore(emails): name the server version the key-scoped routes need Co-Authored-By: Claude Opus 5.5 --- .sampo/changesets/emails-key-scoped-api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.sampo/changesets/emails-key-scoped-api.md b/.sampo/changesets/emails-key-scoped-api.md index 85c3cb124..836028254 100644 --- a/.sampo/changesets/emails-key-scoped-api.md +++ b/.sampo/changesets/emails-key-scoped-api.md @@ -2,4 +2,4 @@ pypi/posthog: patch --- -`posthog.emails` sends emails, uploads attachments and reads email statuses through `/api/messaging/...`, which takes the project from the project secret API key. It no longer calls `/api/projects/@current/messaging/...`, since PostHog is removing the `@current` alias. A self-hosted PostHog older than these routes answers these calls with 404. +`posthog.emails` sends emails, uploads attachments and reads email statuses through `/api/messaging/...`, which takes the project from the project secret API key. It no longer calls `/api/projects/@current/messaging/...`, since PostHog is removing the `@current` 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.