Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(postmark): sync first email opens to the warehouse (#115283)

posthog[bot]c34a03fc85a7
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS.md
index 80c1fb1aca8d..dbfcd6b6aeda 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS.md
@@ -118,7 +118,7 @@ The five narrative patterns below were found in the hand-audited tier 1 and 2 so
Mailchimp has no `email_activity`, `open_details`, `click_details`, or `unsubscribes`.
Klaviyo has no `flow_actions` / `flow_messages` or reporting values endpoints.
Resend has no per-message event table.
- Postmark has no opens/clicks/stats.
+ Postmark has opens but no clicks or stats.
Open and click behavior is usually the entire point of connecting an email tool.
5. **State-transition history is missing almost everywhere.**
@@ -685,10 +685,12 @@ Seventeen tables (10 API endpoints plus 7 webhook event streams) and one of our
### Postmark — needs confirmation
-Five tables. Delivery config is present, engagement is not. `bounces` also accepts pushed rows
-through the Webhooks API (Bounce and SpamComplaint triggers).
+Six tables. Delivery config and first opens are present, clicks are not. `bounces` also accepts
+pushed rows through the Webhooks API (Bounce and SpamComplaint triggers).
-- [ ] Opens and clicks per message.
+- [x] Opens per message (`opens`, first open per recipient, pull only).
+- [ ] Clicks per message.
+- [ ] Open webhook ingestion, so `opens` gets every open and is not capped by the 10,000-row window.
- [ ] Outbound overview stats (sends, bounce rate, open rate, spam complaints).
- [ ] `servers`, `suppressions`, `domains`, inbound rules, `webhooks`.
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/canonical_descriptions.py
index 83402a79bc91..a34882057835 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/canonical_descriptions.py
@@ -70,6 +70,23 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"Subject": "Subject line of the message that bounced.",
},
},
+ "opens": {
+ "description": "The first open of an outbound message by one recipient, recorded when open tracking is on.",
+ "docs_url": "https://postmarkapp.com/developer/api/messages-api#message-opens",
+ "columns": {
+ "RecordType": "Type of record. Always Open.",
+ "MessageID": "ID of the outbound message that was opened.",
+ "Recipient": "Email address of the recipient who opened the message.",
+ "Tag": "Tag of the message that was opened.",
+ "MessageStream": "Message stream the opened message was sent through.",
+ "ReceivedAt": "Time at which the recipient opened the message.",
+ "Platform": "Platform used to open the message (WebMail, Desktop, Mobile, or Unknown).",
+ "Client": "Email client or browser used to open the message, with its name, company, and family.",
+ "OS": "Operating system used to open the message, with its name, company, and family.",
+ "UserAgent": "Full user-agent header the email client sent when it opened the message.",
+ "Geo": "Location derived from the IP address that opened the message, with country, region, city, and coordinates.",
+ },
+ },
"templates": {
"description": "An email template defined in Postmark.",
"docs_url": "https://postmarkapp.com/developer/api/templates-api",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/postmark.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/postmark.py
index 953b73559093..5ec24330e6e5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/postmark.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/postmark.py
@@ -1,7 +1,7 @@
"""Postmark (ActiveCampaign) transactional email source.
Postmark exposes a REST/JSON API at https://api.postmarkapp.com. Server-level resources
-(messages, bounces, templates, message streams) authenticate with a per-server token sent
+(messages, opens, bounces, templates, message streams) authenticate with a per-server token sent
in the `X-Postmark-Server-Token` header.
Sync is full-refresh only. Postmark's list endpoints accept `fromdate`/`todate` filters
@@ -211,7 +211,7 @@ def postmark_source(
return SourceResponse(
name=endpoint,
items=items,
- primary_keys=[config.primary_key],
+ primary_keys=config.primary_keys,
partition_count=1,
partition_size=1,
partition_mode="datetime" if config.partition_key else None,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/settings.py
index 1ca3be6e38e4..dd20a86eec0a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/settings.py
@@ -1,4 +1,4 @@
-from dataclasses import dataclass
+from dataclasses import dataclass, field
from typing import Optional
# Postmark caps `count + offset` at 10,000 on its paginated list endpoints, so a full
@@ -9,14 +9,14 @@ POSTMARK_MAX_WINDOW = 10_000
POSTMARK_MAX_PAGE_SIZE = 500
-@dataclass
+@dataclass # nosemgrep: prefer-frozen-dataclasses -- pre-existing; new field shifts the backlog finding into diff
class PostmarkEndpointConfig:
name: str
path: str
# Key in the JSON response body that holds the list of rows (Postmark wraps every
# list response, e.g. `{"TotalCount": N, "Messages": [...]}`).
data_key: str
- primary_key: str = "ID"
+ primary_keys: list[str] = field(default_factory=lambda: ["ID"])
# Stable datetime field used for partitioning. Never an `updated_at`-style field.
partition_key: Optional[str] = None
# Offset/count-paginated endpoints set a page size (max 500). Flat endpoints return
@@ -29,7 +29,7 @@ POSTMARK_ENDPOINTS: dict[str, PostmarkEndpointConfig] = {
name="messages_outbound",
path="/messages/outbound",
data_key="Messages",
- primary_key="MessageID",
+ primary_keys=["MessageID"],
partition_key="ReceivedAt",
page_size=POSTMARK_MAX_PAGE_SIZE,
),
@@ -37,7 +37,7 @@ POSTMARK_ENDPOINTS: dict[str, PostmarkEndpointConfig] = {
name="messages_inbound",
path="/messages/inbound",
data_key="InboundMessages",
- primary_key="MessageID",
+ primary_keys=["MessageID"],
partition_key="ReceivedAt",
page_size=POSTMARK_MAX_PAGE_SIZE,
),
@@ -45,22 +45,32 @@ POSTMARK_ENDPOINTS: dict[str, PostmarkEndpointConfig] = {
name="bounces",
path="/bounces",
data_key="Bounces",
- primary_key="ID",
+ primary_keys=["ID"],
partition_key="BouncedAt",
page_size=POSTMARK_MAX_PAGE_SIZE,
),
+ "opens": PostmarkEndpointConfig(
+ name="opens",
+ path="/messages/outbound/opens",
+ data_key="Opens",
+ # Opens have no ID of their own. Postmark keeps only the first open per message and
+ # recipient, so the pair is unique.
+ primary_keys=["MessageID", "Recipient"],
+ partition_key="ReceivedAt",
+ page_size=POSTMARK_MAX_PAGE_SIZE,
+ ),
"templates": PostmarkEndpointConfig(
name="templates",
path="/templates",
data_key="Templates",
- primary_key="TemplateId",
+ primary_keys=["TemplateId"],
page_size=POSTMARK_MAX_PAGE_SIZE,
),
"message_streams": PostmarkEndpointConfig(
name="message_streams",
path="/message-streams",
data_key="MessageStreams",
- primary_key="ID",
+ primary_keys=["ID"],
),
}
@@ -71,9 +81,10 @@ ENDPOINTS = tuple(POSTMARK_ENDPOINTS.keys())
# --- Webhook ingestion -------------------------------------------------------------------
#
# Postmark's Bounce and SpamComplaint webhooks serialize the same bounce record the Bounce API
-# lists, field for field, so both feed the `bounces` table. The other triggers (Delivery, Open,
-# Click, SubscriptionChange) describe message events we have no table for, and inbound webhooks
-# are configured on the server rather than through the Webhooks API — neither is wired up.
+# lists, field for field, so both feed the `bounces` table. The `opens` table is pull-only for now.
+# The other triggers (Delivery, Click, SubscriptionChange) describe message events we have no table
+# for, and inbound webhooks are configured on the server rather than through the Webhooks API —
+# neither is wired up.
# Schemas that can be fed by pushed rows as well as the backfill.
WEBHOOK_SCHEMA_NAMES = frozenset({"bounces"})
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/source.py
index d6d6d47cd7fe..4915ebd23df5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/source.py
@@ -72,6 +72,7 @@ You can find your server token under **Servers → (your server) → API Tokens*
The token grants read access to the following server-level resources:
- Outbound messages
- Inbound messages
+- Opens
- Bounces
- Templates
- Message streams
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/tests/test_postmark.py b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/tests/test_postmark.py
index f2a78625ae5b..f8c59d141343 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/tests/test_postmark.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/postmark/tests/test_postmark.py
@@ -156,6 +156,7 @@ class TestEndpointDataKeys:
[
("messages_outbound", "Messages", "MessageID"),
("messages_inbound", "InboundMessages", "MessageID"),
+ ("opens", "Opens", "MessageID"),
("templates", "Templates", "TemplateId"),
("message_streams", "MessageStreams", "ID"),
("bounces", "Bounces", "ID"),
@@ -179,7 +180,7 @@ class TestSourceResponseShape:
def _assert_shape(endpoint: str, response: Any) -> None:
config = POSTMARK_ENDPOINTS[endpoint]
assert response.name == endpoint
- assert response.primary_keys == [config.primary_key]
+ assert response.primary_keys == config.primary_keys
if config.partition_key:
assert response.partition_mode == "datetime"
@@ -270,7 +271,7 @@ class TestWebhookItemsWiring:
# Only bounces has a matching Postmark trigger; the rest must keep polling regardless
# of whether a webhook function exists for the source. Consulting the manager would read
# the database, which the driver blocks, so a clean run shows it was never consulted.
- result = _run(endpoint, [_list_response(endpoint, [{POSTMARK_ENDPOINTS[endpoint].primary_key: "x1"}])])
+ result = _run(endpoint, [_list_response(endpoint, [{POSTMARK_ENDPOINTS[endpoint].primary_keys[0]: "x1"}])])
assert result.raised is None
assert len(result.rows) == 1