diff --git a/.sampo/changesets/emails-flat-send-body.md b/.sampo/changesets/emails-flat-send-body.md new file mode 100644 index 000000000..bf6923081 --- /dev/null +++ b/.sampo/changesets/emails-flat-send-body.md @@ -0,0 +1,5 @@ +--- +pypi/posthog: patch +--- + +`emails.send()` now sends the template ID and distinct ID as top-level fields in the request body. diff --git a/posthog/emails.py b/posthog/emails.py index 72b1ca3ef..c5bb6cec8 100644 --- a/posthog/emails.py +++ b/posthog/emails.py @@ -242,12 +242,12 @@ def _prepare_send( raise ValueError("max_retries must be a nonnegative integer.") payload: dict[str, Any] = { - "template": {"id": str(template_uuid)}, + "template_id": str(template_uuid), "to": to, "message_data": clean(dict(template_data or {})), } if distinct_id is not None: - payload["identifiers"] = {"distinct_id": distinct_id} + payload["distinct_id"] = distinct_id return _PreparedSend( path=_SEND_PATH, body=json.dumps(payload, cls=DatetimeSerializer).encode("utf-8"), diff --git a/posthog/test/test_emails.py b/posthog/test/test_emails.py index 0d2099a86..c0aeac2e8 100644 --- a/posthog/test/test_emails.py +++ b/posthog/test/test_emails.py @@ -99,7 +99,7 @@ def no_sleep(): ( "with_distinct_id", {"distinct_id": "user_123"}, - {"identifiers": {"distinct_id": "user_123"}}, + {"distinct_id": "user_123"}, ), ("without_distinct_id", {}, {}), ] @@ -125,7 +125,7 @@ def test_send_posts_the_template_to_the_app_host(_name, overrides, extra_body): assert request.headers["Idempotency-Key"] == "welcome:user_123" assert request.headers["User-Agent"] == f"posthog-python/{VERSION}" assert json.loads(request.body) == { - "template": {"id": TEMPLATE_ID}, + "template_id": TEMPLATE_ID, "to": "user@example.com", "message_data": {"total": 19.5, "expires_at": "2026-11-20T00:00:00+00:00"}, **extra_body, @@ -423,7 +423,7 @@ def handler(request: httpx.Request) -> httpx.Response: assert seen[0].extensions["timeout"] == dict.fromkeys( ["connect", "read", "write", "pool"], 3 ) - assert json.loads(seen[0].content)["identifiers"] == {"distinct_id": "user_123"} + assert json.loads(seen[0].content)["distinct_id"] == "user_123" @pytest.mark.asyncio