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 .sampo/changesets/emails-key-scoped-api.md
Original file line number Diff line number Diff line change
@@ -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. 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 posthog/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}$")
Expand Down
10 changes: 4 additions & 6 deletions posthog/test/test_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]]

Expand Down Expand Up @@ -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
Expand Down
Loading