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-flat-send-body.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions posthog/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 3 additions & 3 deletions posthog/test/test_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", {}, {}),
]
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
Loading