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(warehouse-sources): add Braze campaign, Canvas and segment analytics tables (#100944)

Tom Owersdda0abb37ca1
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 594fb40f4436..2ee8ee2bd013 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -934,7 +934,7 @@ Note: Source uses the Braintree GraphQL API (payments.braintree-api.com/graphql)
## Braze — gaps
-Today (13): `campaign_analytics`, `campaigns`, `canvas_analytics`, `canvases`, `content_blocks`, `email_templates`, `event_analytics`, `events`, `kpi_dau`, `kpi_mau`, `kpi_new_users`, `kpi_uninstalls`, `segments`
+Today (16): `campaign_analytics`, `campaign_details`, `campaigns`, `canvas_analytics`, `canvas_details`, `canvases`, `content_blocks`, `email_templates`, `event_analytics`, `events`, `kpi_dau`, `kpi_mau`, `kpi_new_users`, `kpi_uninstalls`, `segment_analytics`, `segments`
Diffed against: <https://www.braze.com/docs/sitemap.xml>
@@ -942,16 +942,19 @@ Diffed against: <https://www.braze.com/docs/sitemap.xml>
- [x] `/canvas/data_series` — per-canvas per-step time series; the canvases table is unusable analytically without it (high)
- [x] `/events/data_series` — custom event occurrence time series for the event names already synced (high)
- [x] `/kpi/dau/data_series, /kpi/mau/data_series, /kpi/new_users/data_series, /kpi/uninstalls/data_series` — workspace-level DAU/MAU/new users/uninstalls trends (high)
-- [ ] `/segments/data_series` — segment size over time, the only way to trend audience growth (high)
-- [ ] `/campaigns/details` — enriches the campaign list with message variants, channels, tags and conversion behaviors (high)
-- [ ] `/canvas/details` — canvas step and variant structure needed to attribute canvas analytics (high)
+- [x] `/segments/data_series` — segment size over time, the only way to trend audience growth (high)
+- [x] `/campaigns/details` — enriches the campaign list with message variants, channels, tags and conversion behaviors (high)
+- [x] `/canvas/details` — canvas step and variant structure needed to attribute canvas analytics (high)
- [ ] `/sends/data_series` — per-send_id analytics for API-triggered campaign sends (medium)
- [ ] `/purchases/revenue_series, /purchases/quantity_series, /purchases/product_list` — revenue and purchase counts, plus the product lookup that resolves product ids (medium)
- [ ] `/sessions/data_series` — app session counts by app and date (medium)
- [ ] `/email/unsubscribes and /email/hard_bounces` — deliverability events joinable to campaigns (medium)
- [ ] `/catalogs and /catalogs/{catalog_name}/items` — lookup tables resolving catalog item ids referenced in personalization and purchases (medium)
-Note: Braze has no OpenAPI/llms.txt (llms.txt 404s), so I enumerated every /docs/api/endpoints/\* page from the docs sitemap and then opened the individual pages to read the literal REST paths (confirmed /campaigns/data_series, /canvas/data_series, /segments/data_series, /events/data_series, /sends/data_series, /kpi/dau/data_series, /sessions/data_series, /purchases/revenue_series, /email/unsubscribes, /canvas/details, /catalogs, /custom_attributes). The connector now syncs the campaign, Canvas, custom event and workspace KPI `data\_series` endpoints alongside the six `list` endpoints; the remaining analytics gaps are listed above.
+Note: Braze has no OpenAPI/llms.txt (llms.txt 404s), so I enumerated every /docs/api/endpoints/\* page from the docs sitemap and then opened the individual pages to read the literal REST paths (confirmed /campaigns/data_series, /canvas/data_series, /segments/data_series, /events/data_series, /sends/data_series, /kpi/dau/data_series, /sessions/data_series, /purchases/revenue_series, /email/unsubscribes, /canvas/details, /catalogs, /custom_attributes). The connector now syncs the campaign, Canvas, custom event and workspace KPI `data\_series` endpoints alongside the six `list` endpoints, plus `/segments/data_series` and both `details` endpoints.
+The segment series fans out only over segments with analytics tracking enabled, since Braze keeps no size history for the others.
+`/sends/data_series` is deliberately left out: it needs a `send_id` alongside the `campaign_id`, and Braze mints send IDs at send time (`POST /sends/id/create`) with no endpoint that lists them, so a sync has nothing to enumerate.
+The remaining analytics gaps are listed above.
## Breezometer — adequate
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/braze.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/braze.py
index 9e3535075925..a1637986f0f2 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/braze.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/braze.py
@@ -10,10 +10,12 @@ from requests import Request, Response
from products.warehouse_sources.backend.temporal.data_imports.sources.braze.settings import (
BRAZE_DATA_SERIES_ENDPOINTS,
+ BRAZE_DETAILS_ENDPOINTS,
BRAZE_ENDPOINTS,
DATA_SERIES_HISTORY_DAYS,
DEFAULT_PROBE_TARGET,
BrazeDataSeriesConfig,
+ BrazeDetailsConfig,
BrazeEndpointConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.datetime_utils import parse_datetime_value
@@ -291,15 +293,22 @@ def _series_rows(config: BrazeDataSeriesConfig, parent_id: Optional[str], body:
def _iter_parent_ids(
- api_key: str, base_url: str, config: BrazeDataSeriesConfig, team_id: int, job_id: str
+ api_key: str,
+ base_url: str,
+ parent: str,
+ parent_id_field: str,
+ team_id: int,
+ job_id: str,
+ parent_filter_field: Optional[str] = None,
) -> Iterator[str]:
- assert config.parent is not None and config.parent_id_field is not None
- parent_config = BRAZE_ENDPOINTS[config.parent]
+ parent_config = BRAZE_ENDPOINTS[parent]
paginator, _ = _paginator_for(parent_config)
resource = _list_resource(api_key, base_url, parent_config, team_id, job_id, paginator)
for page in resource:
for item in _normalize_items(parent_config, page):
- value = item.get(config.parent_id_field)
+ if parent_filter_field is not None and not item.get(parent_filter_field):
+ continue
+ value = item.get(parent_id_field)
if isinstance(value, str) and value:
yield value
@@ -326,9 +335,18 @@ def _data_series_rows(
)
url = f"{normalize_base_url(base_url)}{config.path}"
- parent_ids: Iterable[Optional[str]] = (
- _iter_parent_ids(api_key, base_url, config, team_id, job_id) if config.parent else [None]
- )
+ parent_ids: Iterable[Optional[str]] = [None]
+ if config.parent is not None:
+ assert config.parent_id_field is not None
+ parent_ids = _iter_parent_ids(
+ api_key,
+ base_url,
+ config.parent,
+ config.parent_id_field,
+ team_id,
+ job_id,
+ config.parent_filter_field,
+ )
for parent_id in parent_ids:
for ending_at, length in windows:
params: dict[str, Any] = {"length": length, "ending_at": ending_at.isoformat(), **config.params}
@@ -386,6 +404,65 @@ def _braze_data_series_source(
)
+def _details_row(config: BrazeDetailsConfig, parent_id: str, body: dict[str, Any]) -> dict[str, Any]:
+ # `message` only carries the request's own status ("success"), so it is not part of the object.
+ row = {key: value for key, value in body.items() if key != "message"}
+ row[config.parent_id_column] = parent_id
+ _encode_json_fields(row, config.json_object_fields)
+ for name in config.json_array_fields:
+ # Braze documents these as arrays, so an omitted one has to read as an empty array.
+ row[name] = json.dumps(row.get(name) or [])
+ return row
+
+
+def _details_rows(
+ api_key: str, base_url: str, config: BrazeDetailsConfig, team_id: int, job_id: str
+) -> Iterator[list[dict[str, Any]]]:
+ session = make_tracked_session(
+ headers={"Authorization": f"Bearer {api_key}", "Accept": "application/json"},
+ # No redirects: the base URL is customer-supplied, so keep traffic pinned
+ # to the validated host (SSRF hardening).
+ allow_redirects=False,
+ redact_values=(api_key,),
+ )
+ url = f"{normalize_base_url(base_url)}{config.path}"
+
+ for parent_id in _iter_parent_ids(api_key, base_url, config.parent, config.parent_id_field, team_id, job_id):
+ response = session.get(url, params={config.parent_id_param: parent_id})
+ response.raise_for_status()
+ body = response.json()
+ if isinstance(body, dict):
+ yield [_details_row(config, parent_id, body)]
+
+
+def _braze_details_source(api_key: str, base_url: str, endpoint: str, team_id: int, job_id: str) -> SourceResponse:
+ config = BRAZE_DETAILS_ENDPOINTS[endpoint]
+
+ def get_rows() -> Iterator[list[dict[str, Any]]]:
+ # Re-check at run time (not just at source-create) in case the URL was edited or now
+ # resolves to an internal address (SSRF / DNS rebinding). Only enforced on cloud.
+ host_ok, host_err = _is_host_safe(_host_from_url(base_url), team_id)
+ if not host_ok:
+ raise BrazeHostNotAllowedError(host_err or HOST_NOT_ALLOWED_ERROR)
+
+ # No resume checkpoint: a fan-out is only resumable from a stable parent ordering, and
+ # Braze's list endpoints order by last edit time, which moves between pages.
+ yield from _details_rows(api_key, base_url, config, team_id, job_id)
+
+ return SourceResponse(
+ name=endpoint,
+ items=get_rows,
+ primary_keys=[config.parent_id_column],
+ partition_count=1,
+ partition_size=1,
+ partition_mode="datetime" if config.partition_key else None,
+ partition_format="month" if config.partition_key else None,
+ partition_keys=[config.partition_key] if config.partition_key else None,
+ # The parent list is ordered by last edit time, so `created_at` does not run monotonically.
+ sort_mode=None,
+ )
+
+
def braze_source(
api_key: str,
base_url: str,
@@ -396,6 +473,9 @@ def braze_source(
should_use_incremental_field: bool = False,
db_incremental_field_last_value: Optional[Any] = None,
) -> SourceResponse:
+ if endpoint in BRAZE_DETAILS_ENDPOINTS:
+ return _braze_details_source(api_key, base_url, endpoint, team_id, job_id)
+
if endpoint in BRAZE_DATA_SERIES_ENDPOINTS:
return _braze_data_series_source(
api_key,
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/canonical_descriptions.py
index 75b96dbb54c6..6984ec310823 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/canonical_descriptions.py
@@ -111,6 +111,15 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"count": "Number of occurrences of the custom event.",
},
},
+ "segment_analytics": {
+ "description": "A daily series of the estimated size of one segment. Only segments with analytics tracking enabled are synced, because Braze keeps no size history for the others.",
+ "docs_url": "https://www.braze.com/docs/api/endpoints/export/segments/get_segment_analytics/",
+ "columns": {
+ "segment_id": "Identifier of the segment the row describes.",
+ "time": "Date the size was measured on, as an ISO 8601 date.",
+ "size": "Estimated number of users in the segment on this date.",
+ },
+ },
"kpi_dau": {
"description": "A daily series of the number of daily active users across the workspace.",
"docs_url": "https://www.braze.com/docs/api/endpoints/export/kpi/get_kpi_dau_date/",
@@ -143,4 +152,50 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"uninstalls": "Number of uninstalls recorded on this date.",
},
},
+ "campaign_details": {
+ "description": "The full configuration of one campaign — its channels, message variants, tags and conversion behaviors.",
+ "docs_url": "https://www.braze.com/docs/api/endpoints/export/campaigns/get_campaign_details/",
+ "columns": {
+ "campaign_id": "Identifier of the campaign the row describes.",
+ "created_at": "Time at which the campaign was created.",
+ "updated_at": "Time at which the campaign was last updated.",
+ "archived": "Whether the campaign is archived.",
+ "draft": "Whether the campaign is a draft.",
+ "enabled": "Whether the campaign is active.",
+ "has_post_launch_draft": "Whether the campaign has a post-launch draft.",
+ "name": "Name of the campaign.",
+ "description": "Description of the campaign.",
+ "schedule_type": "Type of scheduling action the campaign uses.",
+ "channels": "Channels the campaign sends via.",
+ "first_sent": "Date and hour the campaign first sent.",
+ "last_sent": "Date and hour the campaign last sent.",
+ "tags": "Tag names associated with the campaign.",
+ "teams": "Names of the teams associated with the campaign.",
+ "messages": "Message variants keyed by message variation identifier, JSON-encoded because the keys and channel-specific fields vary per campaign.",
+ "conversion_behaviors": "Conversion event behaviors assigned to the campaign, JSON-encoded.",
+ },
+ },
+ "canvas_details": {
+ "description": "The full structure of one Canvas — its steps, variants, channels and tags.",
+ "docs_url": "https://www.braze.com/docs/api/endpoints/export/canvas/get_canvas_details/",
+ "columns": {
+ "canvas_id": "Identifier of the Canvas the row describes.",
+ "created_at": "Time at which the Canvas was created.",
+ "updated_at": "Time at which the Canvas was last updated.",
+ "name": "Name of the Canvas.",
+ "description": "Description of the Canvas.",
+ "archived": "Whether the Canvas is archived.",
+ "draft": "Whether the Canvas is a draft.",
+ "enabled": "Whether the Canvas is active.",
+ "has_post_launch_draft": "Whether the Canvas has a post-launch draft.",
+ "schedule_type": "Type of scheduling action the Canvas uses.",
+ "first_entry": "Date of the first user entry into the Canvas.",
+ "last_entry": "Date of the most recent user entry into the Canvas.",
+ "channels": "Channels used by the Canvas steps.",
+ "variants": "Canvas variants, each with its name, API identifier and first step identifiers, JSON-encoded.",
+ "tags": "Tag names associated with the Canvas.",
+ "teams": "Names of the teams associated with the Canvas.",
+ "steps": "Canvas steps, each with its name, type, API identifier and next-step paths, JSON-encoded.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/settings.py
index 8752021d59b9..86362bc05419 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/settings.py
@@ -144,6 +144,10 @@ class BrazeDataSeriesConfig:
parent_id_field: Optional[str] = None
parent_id_param: Optional[str] = None
parent_id_column: Optional[str] = None
+ # Parent row field that must be truthy for the parent to have a series at all. Braze only
+ # keeps a size history for segments with analytics tracking switched on, and asking for an
+ # untracked one errors, which would abort the whole fan-out.
+ parent_filter_field: Optional[str] = None
# /canvas/data_series nests its series under `data.stats`; every other series returns `data`
# as a flat list.
shape: DataSeriesShape = "list"
@@ -193,6 +197,18 @@ BRAZE_DATA_SERIES_ENDPOINTS: dict[str, BrazeDataSeriesConfig] = {
parent_id_column="event_name",
partition_key="time",
),
+ "segment_analytics": BrazeDataSeriesConfig(
+ name="segment_analytics",
+ path="/segments/data_series",
+ primary_keys=["segment_id", "time"],
+ max_length_days=100,
+ parent="segments",
+ parent_id_field="id",
+ parent_id_param="segment_id",
+ parent_id_column="segment_id",
+ parent_filter_field="analytics_tracking_enabled",
+ partition_key="time",
+ ),
"kpi_dau": BrazeDataSeriesConfig(
name="kpi_dau",
path="/kpi/dau/data_series",
@@ -220,6 +236,53 @@ BRAZE_DATA_SERIES_ENDPOINTS: dict[str, BrazeDataSeriesConfig] = {
}
+# Braze's `details` endpoints return one object describing a single campaign or Canvas — the
+# variants, steps, channels and conversion behaviors the matching list endpoint leaves out. Each
+# takes only the parent id, so they fan out one request per row of that list endpoint.
+@frozen
+class BrazeDetailsConfig:
+ name: str
+ path: str
+ # The list endpoint supplying the required id, the row field holding it, the query param it
+ # goes in, and the column it lands in.
+ parent: str
+ parent_id_field: str
+ parent_id_param: str
+ parent_id_column: str
+ # Response fields whose keys or member shapes vary per row — the variation map keyed by API
+ # identifier, and the step/variant/behavior lists. JSON-encoded so the column keeps one type.
+ # Split by shape so a field Braze omits still reads as its own empty value.
+ json_object_fields: tuple[str, ...] = ()
+ json_array_fields: tuple[str, ...] = ()
+ # `created_at` never moves once the campaign or Canvas exists.
+ partition_key: Optional[str] = None
+
+
+BRAZE_DETAILS_ENDPOINTS: dict[str, BrazeDetailsConfig] = {
+ "campaign_details": BrazeDetailsConfig(
+ name="campaign_details",
+ path="/campaigns/details",
+ parent="campaigns",
+ parent_id_field="id",
+ parent_id_param="campaign_id",
+ parent_id_column="campaign_id",
+ json_object_fields=("messages",),
+ json_array_fields=("conversion_behaviors",),
+ partition_key="created_at",
+ ),
+ "canvas_details": BrazeDetailsConfig(
+ name="canvas_details",
+ path="/canvas/details",
+ parent="canvases",
+ parent_id_field="id",
+ parent_id_param="canvas_id",
+ parent_id_column="canvas_id",
+ json_array_fields=("variants", "steps"),
+ partition_key="created_at",
+ ),
+}
+
+
def _probe_target(config: BrazeDataSeriesConfig) -> str:
# A data series rejects a request missing its required params, so probe with enough of one to
# get a 200/401/403 back. The fan-out series need a parent id we don't have before syncing,
@@ -233,13 +296,20 @@ def _probe_target(config: BrazeDataSeriesConfig) -> str:
BRAZE_PROBE_TARGETS: dict[str, str] = {
**{name: f"{config.path}?page=0" for name, config in BRAZE_ENDPOINTS.items()},
**{name: _probe_target(config) for name, config in BRAZE_DATA_SERIES_ENDPOINTS.items()},
+ # A details endpoint rejects a request without its parent id, so it probes the list endpoint
+ # its fan-out walks — same reasoning as the fan-out series above.
+ **{name: f"{BRAZE_ENDPOINTS[config.parent].path}?page=0" for name, config in BRAZE_DETAILS_ENDPOINTS.items()},
}
DEFAULT_PROBE_TARGET = BRAZE_PROBE_TARGETS["campaigns"]
-ENDPOINTS = tuple(BRAZE_ENDPOINTS.keys()) + tuple(BRAZE_DATA_SERIES_ENDPOINTS.keys())
+ENDPOINTS = (
+ tuple(BRAZE_ENDPOINTS.keys()) + tuple(BRAZE_DATA_SERIES_ENDPOINTS.keys()) + tuple(BRAZE_DETAILS_ENDPOINTS.keys())
+)
INCREMENTAL_FIELDS: dict[str, list[IncrementalField]] = {
**{name: config.incremental_fields for name, config in BRAZE_ENDPOINTS.items()},
**dict.fromkeys(BRAZE_DATA_SERIES_ENDPOINTS, DATA_SERIES_INCREMENTAL_FIELDS),
+ # A details endpoint takes only the parent id — no server-side time filter, so full refresh.
+ **dict.fromkeys(BRAZE_DETAILS_ENDPOINTS, []),
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/source.py
index d4f3f7347e45..b7fd7e5bdc1c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/source.py
@@ -66,9 +66,12 @@ class BrazeSource(ResumableSource[BrazeSourceConfig, BrazeResumeConfig]):
You can create a REST API key in your Braze dashboard under **Settings → API Keys**. Grant the following endpoint permissions for the data you want to sync:
- `campaigns.list`
- `campaigns.data_series`
+- `campaigns.details`
- `canvas.list`
- `canvas.data_series`
+- `canvas.details`
- `segments.list`
+- `segments.data_series`
- `events.list`
- `events.data_series`
- `kpi.dau.data_series`
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/tests/test_braze.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/tests/test_braze.py
index c3908812f507..6edbc0f8f797 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/tests/test_braze.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/tests/test_braze.py
@@ -13,6 +13,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.braze.braz
BrazeHostNotAllowedError,
BrazeResumeConfig,
_canvas_series_rows,
+ _details_row,
_format_modified_after,
_normalize_items,
_series_rows,
@@ -24,6 +25,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.braze.braz
)
from products.warehouse_sources.backend.temporal.data_imports.sources.braze.settings import (
BRAZE_DATA_SERIES_ENDPOINTS,
+ BRAZE_DETAILS_ENDPOINTS,
BRAZE_ENDPOINTS,
DATA_SERIES_HISTORY_DAYS,
)
@@ -635,6 +637,36 @@ class TestDataSeriesRequests:
# The breakdowns are what make the table usable per step and per variant.
assert all(p["include_step_breakdown"] == "true" and p["include_variant_breakdown"] == "true" for p in params)
+ @mock.patch(SESSION_PATCH)
+ def test_segment_series_skips_segments_without_analytics_tracking(self, MockSession):
+ # Braze keeps no size history for an untracked segment, and asking for one errors — which
+ # would abort the fan-out partway through every other segment.
+ session = MockSession.return_value
+ _wire(
+ session,
+ [
+ _response(
+ {
+ "segments": [
+ {"id": "s1", "analytics_tracking_enabled": True},
+ {"id": "s2", "analytics_tracking_enabled": False},
+ {"id": "s3", "analytics_tracking_enabled": True},
+ ]
+ }
+ ),
+ _response({"segments": []}),
+ ],
+ )
+ session.get.side_effect = [
+ _series_response([{"time": "2026-03-09", "size": 10}]),
+ _series_response([{"time": "2026-03-09", "size": 20}]),
+ ]
+
+ rows = _rows(_source("segment_analytics"))
+
+ assert [row["segment_id"] for row in rows] == ["s1", "s3"]
+ assert [call.kwargs["params"]["segment_id"] for call in session.get.call_args_list] == ["s1", "s3"]
+
@mock.patch(SESSION_PATCH)
def test_uses_no_redirect_session_with_redacted_key(self, MockSession):
session = MockSession.return_value
@@ -689,3 +721,138 @@ class TestBrazeDataSeriesSourceResponse:
session.get.side_effect = [_series_response([])]
assert _source("kpi_dau").sort_mode is None
+
+
+class TestDetailsRows:
+ @pytest.mark.parametrize("config", list(BRAZE_DETAILS_ENDPOINTS.values()))
+ def test_injects_the_parent_id_and_drops_the_status_envelope(self, config):
+ row = _details_row(config, "p1", {"message": "success", "name": "Welcome"})
+
+ assert row[config.parent_id_column] == "p1"
+ assert "message" not in row
+ assert row["name"] == "Welcome"
+
+ @pytest.mark.parametrize("config", list(BRAZE_DETAILS_ENDPOINTS.values()))
+ def test_varying_shapes_are_encoded_as_json(self, config):
+ # The variation map is keyed by API identifier and the step/variant lists differ per row,
+ # so the column has to hold one type across every row.
+ fields = (*config.json_object_fields, *config.json_array_fields)
+ row = _details_row(config, "p1", dict.fromkeys(fields, [{"id": "x"}]))
+
+ for name in fields:
+ assert row[name] == '[{"id": "x"}]'
+
+ @pytest.mark.parametrize("config", list(BRAZE_DETAILS_ENDPOINTS.values()))
+ def test_missing_json_field_keeps_its_own_empty_shape(self, config):
+ # An omitted array must not read as an object, or the column's JSON type flips per row.
+ row = _details_row(config, "p1", {"name": "Welcome"})
+
+ for name in config.json_object_fields:
+ assert row[name] == "{}"
+ for name in config.json_array_fields:
+ assert row[name] == "[]"
+
+
+class TestDetailsRequests:
+ @mock.patch(SESSION_PATCH)
+ def test_campaign_details_fans_out_over_the_campaign_list(self, MockSession):
+ session = MockSession.return_value
+ _wire(session, [_response({"campaigns": [{"id": "c1"}, {"id": "c2"}]}), _response({"campaigns": []})])
+ session.get.side_effect = [
+ _response({"message": "success", "name": "Welcome", "channels": ["email"]}),
+ _response({"message": "success", "name": "Winback", "channels": ["sms"]}),
+ ]
+
+ rows = _rows(_source("campaign_details"))
+
+ assert rows == [
+ {
+ "campaign_id": "c1",
+ "name": "Welcome",
+ "channels": ["email"],
+ "messages": "{}",
+ "conversion_behaviors": "[]",
+ },
+ {
+ "campaign_id": "c2",
+ "name": "Winback",
+ "channels": ["sms"],
+ "messages": "{}",
+ "conversion_behaviors": "[]",
+ },
+ ]
+ assert [call.args[0] for call in session.get.call_args_list] == [f"{BASE_URL}/campaigns/details"] * 2
+ assert [call.kwargs["params"] for call in session.get.call_args_list] == [
+ {"campaign_id": "c1"},
+ {"campaign_id": "c2"},
+ ]
+
+ @mock.patch(SESSION_PATCH)
+ def test_canvas_details_carries_the_step_and_variant_structure(self, MockSession):
+ session = MockSession.return_value
+ _wire(session, [_response({"canvases": [{"id": "cv1"}]}), _response({"canvases": []})])
+ session.get.side_effect = [
+ _response(
+ {
+ "message": "success",
+ "created_at": "2026-01-02T03:04:05Z",
+ "variants": [{"id": "v1", "name": "Variant 1"}],
+ "steps": [{"id": "st1", "type": "Message"}],
+ }
+ )
+ ]
+
+ rows = _rows(_source("canvas_details"))
+
+ assert rows == [
+ {
+ "canvas_id": "cv1",
+ "created_at": "2026-01-02T03:04:05Z",
+ "variants": '[{"id": "v1", "name": "Variant 1"}]',
+ "steps": '[{"id": "st1", "type": "Message"}]',
+ }
+ ]
+ assert session.get.call_args.kwargs["params"] == {"canvas_id": "cv1"}
+
+ @mock.patch(SESSION_PATCH)
+ def test_raises_on_an_error_status(self, MockSession):
+ # raise_for_status keeps the 403 wording get_non_retryable_errors matches on.
+ session = MockSession.return_value
+ _wire(session, [_response({"campaigns": [{"id": "c1"}]}), _response({"campaigns": []})])
+ session.get.side_effect = [_response({"message": "forbidden"}, status_code=403)]
+
+ with pytest.raises(HTTPError, match="403 Client Error"):
+ _rows(_source("campaign_details"))
+
+ @mock.patch(HOST_SAFE_PATCH)
+ @mock.patch(SESSION_PATCH)
+ def test_raises_when_host_not_allowed(self, MockSession, mock_host_safe):
+ mock_host_safe.return_value = (False, "host not allowed")
+
+ response = braze_source(
+ "key",
+ "https://10.0.0.1",
+ "campaign_details",
+ team_id=42,
+ job_id="job",
+ resumable_source_manager=_make_manager(),
+ )
+ with pytest.raises(BrazeHostNotAllowedError):
+ list(cast("Iterable[Any]", response.items()))
+
+ MockSession.return_value.get.assert_not_called()
+
+
+class TestBrazeDetailsSourceResponse:
+ @pytest.mark.parametrize("endpoint", list(BRAZE_DETAILS_ENDPOINTS))
+ def test_keyed_on_the_parent_id_and_partitioned_on_creation(self, endpoint):
+ config = BRAZE_DETAILS_ENDPOINTS[endpoint]
+ response = _source(endpoint)
+
+ # One row per parent, so the injected parent id is the whole key.
+ assert response.primary_keys == [config.parent_id_column]
+ assert config.partition_key == "created_at"
+ assert response.partition_mode == "datetime"
+ assert response.partition_keys == ["created_at"]
+ # The parent list is ordered by last edit time, so rows do not arrive by `created_at`.
+ assert response.sort_mode is None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/tests/test_braze_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/tests/test_braze_source.py
index b62ed61e00b9..e69d9d8cf589 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/braze/tests/test_braze_source.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/braze/tests/test_braze_source.py
@@ -3,6 +3,7 @@ from unittest import mock
from products.warehouse_sources.backend.temporal.data_imports.sources.braze.settings import (
BRAZE_DATA_SERIES_ENDPOINTS,
+ BRAZE_DETAILS_ENDPOINTS,
DATA_SERIES_LOOKBACK_SECONDS,
ENDPOINTS,
)
@@ -52,6 +53,11 @@ class TestBrazeSource:
# Templates/content blocks expose Braze's server-side `modified_after` filter; every data
# series is bounded by its own `ending_at`/`length` window.
assert incremental == {"email_templates", "content_blocks", *BRAZE_DATA_SERIES_ENDPOINTS}
+ # A details endpoint takes only its parent id, so there is nothing to sync incrementally.
+ for name in BRAZE_DETAILS_ENDPOINTS:
+ details = next(schema for schema in schemas if schema.name == name)
+ assert details.supports_incremental is False
+ assert details.supports_append is False
def test_data_series_schemas_re_read_a_trailing_window_and_never_append(self):
schemas = {schema.name: schema for schema in self.source.get_schemas(self.config, self.team_id)}
@@ -95,6 +101,10 @@ class TestBrazeSource:
("campaign_analytics", "/campaigns/list?page=0"),
("canvas_analytics", "/canvas/list?page=0"),
("event_analytics", "/events/list?page=0"),
+ ("segment_analytics", "/segments/list?page=0"),
+ # A details endpoint rejects a request without its parent id, so it probes the same way.
+ ("campaign_details", "/campaigns/list?page=0"),
+ ("canvas_details", "/canvas/list?page=0"),
],
)
@mock.patch(