diff --git a/.sampo/changesets/emails-key-scoped-api.md b/.sampo/changesets/emails-key-scoped-api.md new file mode 100644 index 000000000..836028254 --- /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. Needs PostHog Cloud, or a self-hosted PostHog from 2026-11-18 or later. Older self-hosted versions answer these calls with a 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