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(messaging): import customer.io suppressions with the customer.io import (#123567)

Harley Alexander1a9b76a90d1e
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index ec18ef9120f4..44b3f302c69e 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -8349,57 +8349,57 @@ snapshots:
products-wizard-wizard-run-sync-card--running--light:
hash: v1.k794b7964.df30028d9399928f4b1c8d2ad87fadb9ce6597419600e07b57b35d34ac9ade93.zpJJ3MjyG1rhJm9eAq8JTYdRRteI3ptNuZor2nr8hOA
products-workflows-customerioimportmodal--all-steps-completed--dark:
- hash: v1.k794b7964.da9d1ebf1836700267307224631511bd8fe3b9fb0906654a383e545e1c6f98f1.lPijIVizKAMxsGEVt28x0Y5izfhcfnbjbPhoHzriWFg
+ hash: v1.k794b7964.4433daf4a6f3ad289f37cbc466609a947b254f8b3a027357d05e00a725c57fa9.06a8j_j5NyzCTMMcfO3UH1b6ZIvt9oDgSBHpTJ6JOFk
products-workflows-customerioimportmodal--all-steps-completed--light:
- hash: v1.k794b7964.aba3fcf8b7e329df94308d5d78ecf37eb8038c20526ad0f13834a3af9d04f9c4.Q-SJDHSp5RHvykZVvswlBHM__enEdBS5h-XQxeO65dw
+ hash: v1.k794b7964.c3dbb9dae7cd1203796116cb526801615f04fff783d8a85807565b88dedb43a6.eknEgwDIHMqZsbEDNExQKFjd4Fx4IOYxx5las4kbpak
products-workflows-customerioimportmodal--both-steps-completed--dark:
- hash: v1.k794b7964.bd010c39467624b7d37b16cb55e4f580c227ec8d56dd7e264ed77b5fd2b26614.YAb5d7v90P4uD_xTakm-jeEKeu5t_pUcDXj_sVPRmEs
+ hash: v1.k794b7964.18d4074d6f34f00e57f33fabd42598af0626d23e5dccf8df4d5bb9bd32032694.a_oP596DTN7Rw2p4bWrv8tHHX_paCILz8Uuevnjzx-0
products-workflows-customerioimportmodal--both-steps-completed--light:
- hash: v1.k794b7964.ecb70391143608f6824db053b725f313dbb8fad9b4ad8c83952f5c0d62fa7014.MlstSGI-DIGctJ--kG0cz84aX7xby-DuXg9mVC5adHU
+ hash: v1.k794b7964.20cc443a6beb23987451e59d9e37dc5fd6c9edac12070f734c6794085b00a4ef.0j8fLlKs25AL50C_hHxlyOCykMqHir6E4AyrsQP9MyY
products-workflows-customerioimportmodal--both-steps-not-completed--dark:
- hash: v1.k794b7964.08c0f848d3c7021bcdb4609921a7bcc4053806f4eaf1162bc4740e501c59db31.gZDyENpWXFV8SlhItEqK8G2yw7kEAOv2EMVcQ08tCcQ
+ hash: v1.k794b7964.ea5155a38680b44a133382c65e04c769f83c65fc39b9e6755ffd32886c3050c1.kPCkKfbt0yvdjTV8VJn_CxXAYIoek_yy07zyItt9Itc
products-workflows-customerioimportmodal--both-steps-not-completed--light:
- hash: v1.k794b7964.393888fac2a2c189acb10cd700e4a2162907c8c60daea2e8969a39c2dce89684.2WGADmgYvN4gabWOFsxfvQFAVS4EXXLmiGtoQmRgnzk
+ hash: v1.k794b7964.1df6ca04972f8b0d0b0c517ce16d6924fe27254f359cc0c8e16e816cea95d56c.GQootOFxJjyqS8jojYyVBjB5IY92XYB_MYa0bDIA9s8
products-workflows-customerioimportmodal--step-1-completed--dark:
- hash: v1.k794b7964.a36fb26a64de89a6760ac18e2b1bb071e452bae1964c287b2a1544bb8b3bac63.hzXPSTM4_RMLOSoxV_X2XhBKgFJjKM-GgwiooUk63mw
+ hash: v1.k794b7964.c83846d9a55e8de54910a1334c52aa8dd46108c77d73826d694e3a8b113b75f6.x7ONobAIrfQGWsfDxcoRtXBqw0UA-6GqPlyhg17HRiY
products-workflows-customerioimportmodal--step-1-completed--light:
- hash: v1.k794b7964.47481419926ab9d3a61eeb6eab75c3b7a05c6e9aa24a51b9e999af1645d2169b.TvXZIMC0mPhND-aSpNb8KxAMwtl-EKBy9EbRTXhVvVs
+ hash: v1.k794b7964.0adabaee75d85de6f604790196ffd8a8a00912a09a833c2cc6d9ff709c6c81a5.lunQob10e5tUhluIfV0FAJDLyLUulvWlv-p2xub_mtQ
products-workflows-customerioimportmodal--step-1-completed-but-key-deleted--dark:
- hash: v1.k794b7964.a36fb26a64de89a6760ac18e2b1bb071e452bae1964c287b2a1544bb8b3bac63.EJSZijvmaVhycK0sR2_suTkE3i4QExVgNZY87x4HfU0
+ hash: v1.k794b7964.c83846d9a55e8de54910a1334c52aa8dd46108c77d73826d694e3a8b113b75f6.4h0p2eqhP45sxjJmQtF4fflM-9Y14ic2FRWvu0_j4UY
products-workflows-customerioimportmodal--step-1-completed-but-key-deleted--light:
- hash: v1.k794b7964.47481419926ab9d3a61eeb6eab75c3b7a05c6e9aa24a51b9e999af1645d2169b.CkMSbId6wTs2b3Uy1lUZDNqrIvXlAvWf_5WuYSEiL5k
+ hash: v1.k794b7964.0adabaee75d85de6f604790196ffd8a8a00912a09a833c2cc6d9ff709c6c81a5.CF0ilRdQv5qdGUtHzOkP2_-qRn5TY1CtfJFE4JfYZWk
products-workflows-customerioimportmodal--step-1-failed-invalid-key--dark:
- hash: v1.k794b7964.fdaa3c57c39524f2361eab674982ea1fb2db88a52c6d3cd1055fa0ab3d47f177.KMdfq0YYMZgIfhMHuzrU9ko7NgZlQFIZF9SzKeGa8K8
+ hash: v1.k794b7964.32e5f574a55a220f5ced43ac0354016ad0dc007cd316893b4d01535b656b892d.fbvMccZ3Et_z3Gi1PtMvazjqohLZyQehZ7bw8VXGdH8
products-workflows-customerioimportmodal--step-1-failed-invalid-key--light:
- hash: v1.k794b7964.2ddd50f9e82f6b08bfbcb70c5e830b121314dab6a9ae3af4aaf8d7460b08604a.6gYabAKqTVwZ8xNP2BaAEULOIwUJqUdrCLDD0b4KEx8
+ hash: v1.k794b7964.dfe3011ed7685ab4cc32f428eaebabbc2b60e76e239dcf24a313b2b1766cce60.d-AeRIQqFFsmArkstmOeeial2IFUJENPD84i1R3OZ_A
products-workflows-customerioimportmodal--step-2-failed--dark:
- hash: v1.k794b7964.d625e66bc9e55b657742e513763e7e8f66e98c71829a1539913666f08abbcc45.mp48_OFJSesSHRfERFqkm29tdkG4-bzL4bjGDvRf-kk
+ hash: v1.k794b7964.5954f25a54c9231a589e95b7a5681c5845164b364d7780b98f790d4e7b8cad51.FADC2Ak1J5M2ul7suwjNfZra05AwFrvqgf1C1leCBrI
products-workflows-customerioimportmodal--step-2-failed--light:
- hash: v1.k794b7964.ff0185f12bb2f117561f00e337987e2f1172c6aa3f0983335c7cccb23b6ad4cc.KaRSr_QKiXt1MRc_hf8jAyyN8-Ugkf3y-ksuPx87rVk
+ hash: v1.k794b7964.5091f689891e9a8ebc4ce9dbadefd0d7e6399afbfeec9640e14d0314a0c19e7f._ELceF-weVnL800CQVY8adJBbhEedS-BVWZn8ug_9L8
products-workflows-customerioimportmodal--step-3-webhook-disabled--dark:
- hash: v1.k794b7964.a1353c2d772cf04478d2100ffc155bde44a2f3a76f61258e0d3475c7c1a75177.41SXADGQjvFj4XPsbZGSFow12vyIketbLIx4dXII4Zo
+ hash: v1.k794b7964.1979328a3a84456bdd1e46e291d95741dbd46f650cf75deb5e3f1e0aae145b34.bXPsK8Rug7VbFBjTF6aJV6faGLvJGUnlW60Cfo4_yXM
products-workflows-customerioimportmodal--step-3-webhook-disabled--light:
- hash: v1.k794b7964.311befc74334a58176166846bb0649742ed22dc6798cc50b23bcafa79f2a90e6.b93ZuHEHCOK9ZEYGUBLaEeGH1FttUmd6mYY3MB8sXAA
+ hash: v1.k794b7964.4a992be4c6c8a7632a50ed7ec8066c98b09cb0b8dd00ce814fbe5247636f9c47.hwaNF_NJjqoXp8Zzu_ZrW7d6oirXNHvUZHP8o6LhAwc
products-workflows-customerioimportmodal--step-3-webhook-enabled--dark:
- hash: v1.k794b7964.d553cecf3e544087316e1687404c8e2b3a6c19f618a05e09880e60e656054f23.mNzTyjIAQIrKC1gGhUZoyPHwejtHYk4Py8Mq0CHkIUk
+ hash: v1.k794b7964.a29a65d52ec2df3192fc6cbf2a64c66c28630aaded389abac4f6270b5354862a.6YwVpRYbCrung_pX55ZpCDF4mmaYY69nlA-cOkuDRy8
products-workflows-customerioimportmodal--step-3-webhook-enabled--light:
- hash: v1.k794b7964.0954891b73cdc0b1bce1275fa11a5fa4af2055b83b518bce82f3fde886097659.kIhzBTzXj4WZdh-uK6b5axnPMcDhEbbT0zl0Wa_FEp0
+ hash: v1.k794b7964.5b7c112259dff497c28acddbf632dd3ea2b954c63cda13dc41c7fb0ecf9239b6.z7QTvSWW0BwyMPmSTnREew2niMSdNJC1LflBw40HvB0
products-workflows-customerioimportmodal--step-3-webhook-not-configured--dark:
- hash: v1.k794b7964.bd010c39467624b7d37b16cb55e4f580c227ec8d56dd7e264ed77b5fd2b26614.aRcC2bfwykXS64ov-rLEJlRbT5gJdGFq67Psjl2nIbU
+ hash: v1.k794b7964.18d4074d6f34f00e57f33fabd42598af0626d23e5dccf8df4d5bb9bd32032694.WW-OMYE0dCTVRmViWKOXZwmg_nsgLjwQeOVBwZ5YRLk
products-workflows-customerioimportmodal--step-3-webhook-not-configured--light:
- hash: v1.k794b7964.ecb70391143608f6824db053b725f313dbb8fad9b4ad8c83952f5c0d62fa7014.s_vMUGhMUmoad01-1QoUAAx1D7ddvoKZ3rwmWoBmhyo
+ hash: v1.k794b7964.20cc443a6beb23987451e59d9e37dc5fd6c9edac12070f734c6794085b00a4ef.vxsV9Pmue9Jjo0QxbiQJWdMj4GJxviridtSWDTk6SMI
products-workflows-customerioimportmodal--step-4-track-disabled--dark:
- hash: v1.k794b7964.5a29f1d4cdbe38190c949ab54e3ee4fff006d21fc928ec8ff5c68d8fc5d7627b.SDa1W1nUzucaabz0pUYL_qDBmksfE1doDy3BU6KDqqw
+ hash: v1.k794b7964.b0f87ec8fc4a02e516253e4f52a1ebaec6ba6715713d66d94822525f2f65ed57.eqJZHM2m1jpmp-b6MflxB1Zv5K47y-HI1e7CXchNGnQ
products-workflows-customerioimportmodal--step-4-track-disabled--light:
- hash: v1.k794b7964.e11d177daec797a524de34c9f7203bef84f626074cbf5b83842fd0c595d769f9.UG-H6Cooww1CZtXT8UbvDwx46D-ExSk_feMpKb4wD10
+ hash: v1.k794b7964.ef689dc5b8046e8992fe42d0d5df2ed0f26c009214bdd9ac7efd805facad37ce.nc3dI6AN-uhl7cXq3pmS3xIWDgSvPnprP78BwFS3P8c
products-workflows-customerioimportmodal--step-4-track-enabled--dark:
- hash: v1.k794b7964.da9d1ebf1836700267307224631511bd8fe3b9fb0906654a383e545e1c6f98f1.vulam-laas3LHqDbysuhrVaTqvxEAUveKNcmN7fHijE
+ hash: v1.k794b7964.4433daf4a6f3ad289f37cbc466609a947b254f8b3a027357d05e00a725c57fa9.BVTyZ5JLAISYti_rHFlEyG_o5WOw3WGQ3OAt9Qc9VE8
products-workflows-customerioimportmodal--step-4-track-enabled--light:
- hash: v1.k794b7964.aba3fcf8b7e329df94308d5d78ecf37eb8038c20526ad0f13834a3af9d04f9c4.j3g3sIq072YM72X9YTLCZbCjoAzCHc1IGDCkdQqVqlg
+ hash: v1.k794b7964.c3dbb9dae7cd1203796116cb526801615f04fff783d8a85807565b88dedb43a6.KfK-rDK5BQ0dfoptdYvFkC3Q7Qtk9AU4NyJ84sySgBE
products-workflows-customerioimportmodal--step-4-track-not-configured--dark:
- hash: v1.k794b7964.d553cecf3e544087316e1687404c8e2b3a6c19f618a05e09880e60e656054f23.hNkLLb04XLyd-PQJa59WwPhgRAxMbW5fSDzCnowJKBs
+ hash: v1.k794b7964.a29a65d52ec2df3192fc6cbf2a64c66c28630aaded389abac4f6270b5354862a.KAr3zl_uLA4J-v6K8p0Fkw7-JNFOpzpYIRWwvqR4JCI
products-workflows-customerioimportmodal--step-4-track-not-configured--light:
- hash: v1.k794b7964.0954891b73cdc0b1bce1275fa11a5fa4af2055b83b518bce82f3fde886097659.mgEq2W8sZg7x-vt8z2EpwEHPBGRzPI1GWtn-9tu-46o
+ hash: v1.k794b7964.5b7c112259dff497c28acddbf632dd3ea2b954c63cda13dc41c7fb0ecf9239b6.3syPLP3AOmxzQt_gndIfTA9Y4n3r8qT3-2sn_g3gN8M
products-workflows-editor-configuration-panel--build--dark:
hash: v1.k794b7964.ba77097ed29985565b93fbc6783a05e1d057fe5a12779705eaa6d744aa77cfb7.dXBhkcHPwydmzF6HM-fUZqF060li4rZDdMxjFRtqwjQ
products-workflows-editor-configuration-panel--build--light:
diff --git a/products/messaging/backend/services/customerio_client.py b/products/messaging/backend/services/customerio_client.py
index c531b2a9080b..7d5237554f0f 100644
--- a/products/messaging/backend/services/customerio_client.py
+++ b/products/messaging/backend/services/customerio_client.py
@@ -84,6 +84,15 @@ class CustomerIOClient:
filter_conditions = {"attribute": {"field": "unsubscribed", "operator": "eq", "value": True}}
return self.search_customers(filter_conditions, limit, start)
+ def get_suppressions(self, suppression_type: str, limit: int = 1000, offset: int = 0) -> list[dict[str, Any]]:
+ """One page of the addresses Customer.io's email provider suppressed for `suppression_type`: `bounces`,
+ `blocks`, `spam_reports` or `invalid_emails`. Each entry has `email`, `created`, `reason` and `status`."""
+ response = self._make_request(
+ "GET", f"/esp/suppression/{suppression_type}", params={"limit": min(limit, 1000), "offset": offset}
+ )
+ suppressions = response.get("suppressions")
+ return suppressions if isinstance(suppressions, list) else []
+
def validate_credentials(self) -> bool:
try:
# Try a simple API call to validate credentials
diff --git a/products/messaging/backend/services/customerio_config.py b/products/messaging/backend/services/customerio_config.py
index 8bacd5780d8d..81753f46f8ae 100644
--- a/products/messaging/backend/services/customerio_config.py
+++ b/products/messaging/backend/services/customerio_config.py
@@ -56,6 +56,8 @@ def import_from_customerio(team_id: int, app_api_key: str | None, created_by_id:
"imported_at": timezone.now().isoformat(),
"categories_created": result.get("categories_created", 0),
"globally_unsubscribed_count": result.get("globally_unsubscribed_count", 0),
+ "suppressions_imported": result.get("suppressions_imported", 0),
+ "errors": result.get("errors", []),
}
else:
errors = result.get("errors", [])
diff --git a/products/messaging/backend/services/customerio_import_service.py b/products/messaging/backend/services/customerio_import_service.py
index 6f219b8c9a29..20fcafbba4bd 100644
--- a/products/messaging/backend/services/customerio_import_service.py
+++ b/products/messaging/backend/services/customerio_import_service.py
@@ -1,10 +1,14 @@
import io
import csv
import json
+import time
import logging
from typing import Any, Optional
from django.db import transaction
+from django.utils import timezone
+
+from posthog.models.scoping.manager import resolve_effective_team_id
from products.messaging.backend.models.message_category import MessageCategory, MessageCategoryType
from products.messaging.backend.models.message_preferences import (
@@ -12,11 +16,24 @@ from products.messaging.backend.models.message_preferences import (
MessageRecipientPreference,
PreferenceStatus,
)
+from products.messaging.backend.models.message_suppression import MessageSuppression, SuppressionSource
from .customerio_client import CustomerIOClient
logger = logging.getLogger(__name__)
+# Customer.io suppression lists to import, with the suppression source and reason each one maps to. A bounced or
+# invalid address can't receive mail, so it blocks every email. A spam report blocks marketing email only. Blocks
+# are not imported, because a provider block is often temporary.
+CUSTOMERIO_SUPPRESSION_TYPES: dict[str, tuple[SuppressionSource, str]] = {
+ "bounces": (SuppressionSource.BOUNCE, "Imported from Customer.io (bounced)"),
+ "invalid_emails": (SuppressionSource.BOUNCE, "Imported from Customer.io (invalid address)"),
+ "spam_reports": (SuppressionSource.COMPLAINT, "Imported from Customer.io (spam report)"),
+}
+SUPPRESSION_PAGE_SIZE = 1000
+# Customer.io allows 10 App API requests per second.
+SUPPRESSION_PAGE_DELAY_SECONDS = 0.2
+
class CustomerIOImportService:
def __init__(self, team_id: int, api_key: Optional[str], created_by_id: Optional[int]):
@@ -34,12 +51,13 @@ class CustomerIOImportService:
"customers_processed": 0,
"preferences_updated": 0,
"globally_unsubscribed_count": 0,
+ "suppressions_imported": 0,
"errors": [],
"details": "",
}
def import_api_data(self) -> dict[str, Any]:
- """Import categories and globally unsubscribed users via API"""
+ """Import categories, globally unsubscribed users and suppressed addresses via API"""
if not self.api_key:
self.progress["status"] = "failed"
self.progress["errors"].append("API key is required for Customer.io API import")
@@ -69,6 +87,9 @@ class CustomerIOImportService:
# Step 3: Process globally unsubscribed users
self._process_globally_unsubscribed_users()
+ # Step 4: Import addresses Customer.io's email provider suppressed
+ self._import_suppressions()
+
self.progress["status"] = "completed"
except Exception as e:
@@ -393,6 +414,66 @@ class CustomerIOImportService:
self.progress["details"] = f"Processed {total_processed} globally unsubscribed users"
+ def _import_suppressions(self) -> None:
+ """Add Customer.io's bounced, invalid and spam-reported addresses to the suppression list.
+
+ Without them, the first send to each of these addresses after moving to Workflows bounces again, and the
+ bounces count against the shared sender reputation.
+ """
+ if not self.client:
+ return
+
+ # bulk_create skips the save() that moves a child environment's rows to its parent project.
+ team_id = resolve_effective_team_id(self.team_id)
+ for suppression_type, (source, reason) in CUSTOMERIO_SUPPRESSION_TYPES.items():
+ offset = 0
+ while True:
+ try:
+ page = self.client.get_suppressions(suppression_type, limit=SUPPRESSION_PAGE_SIZE, offset=offset)
+ except Exception as e:
+ self.progress["errors"].append(f"Error importing Customer.io {suppression_type}: {str(e)[:200]}")
+ break
+
+ emails = sorted(
+ {
+ email.strip().lower()
+ for entry in page
+ if isinstance(entry, dict) and isinstance(email := entry.get("email"), str) and "@" in email
+ }
+ )
+ if emails:
+ self.progress["suppressions_imported"] += self._add_suppressions(team_id, emails, source, reason)
+ if len(page) < SUPPRESSION_PAGE_SIZE:
+ break
+ offset += len(page)
+ time.sleep(SUPPRESSION_PAGE_DELAY_SECONDS)
+
+ def _add_suppressions(self, team_id: int, emails: list[str], source: SuppressionSource, reason: str) -> int:
+ """Suppress the addresses that have no suppression row yet, and return how many it added.
+
+ An existing row is left alone. It can be a manual entry, an address someone removed from the list on
+ purpose, or a row the bounce feedback already manages.
+ """
+ suppressions = MessageSuppression.objects.for_team(team_id, canonical=True)
+ existing = set(suppressions.filter(identifier__in=emails).values_list("identifier", flat=True))
+ now = timezone.now()
+ new_rows = [
+ MessageSuppression(
+ team_id=team_id,
+ identifier=email,
+ source=source,
+ reason=reason,
+ suppressed=True,
+ suppressed_at=now,
+ created_by_id=self.created_by_id,
+ )
+ for email in emails
+ if email not in existing
+ ]
+ # ignore_conflicts covers an address the bounce feedback inserts between the read above and this write.
+ suppressions.bulk_create(new_rows, batch_size=500, ignore_conflicts=True)
+ return len(new_rows)
+
def _bulk_update_all_preferences(self, emails: list[str], category_ids: list[str]) -> None:
"""Bulk update preferences to opt out users from ALL categories"""
try:
diff --git a/products/messaging/backend/services/test_customerio_import_service.py b/products/messaging/backend/services/test_customerio_import_service.py
index 0aa4f01d489e..f0cf9b76c080 100644
--- a/products/messaging/backend/services/test_customerio_import_service.py
+++ b/products/messaging/backend/services/test_customerio_import_service.py
@@ -5,13 +5,17 @@ from unittest.mock import MagicMock, patch
from parameterized import parameterized
+from posthog.models import Team
+
from products.messaging.backend.models.message_category import MessageCategory, MessageCategoryType
from products.messaging.backend.models.message_preferences import (
ALL_MESSAGE_PREFERENCE_CATEGORY_ID,
MessageRecipientPreference,
PreferenceStatus,
)
+from products.messaging.backend.models.message_suppression import MessageSuppression, SuppressionSource
+from .customerio_client import CustomerIOAPIError
from .customerio_import_service import CustomerIOImportService
@@ -285,6 +289,57 @@ [email protected],cio_6,"{""topics"": {""topic_1"": true, ""topic_2"": true}}"
preference = MessageRecipientPreference.objects.get(team=self.team, identifier="[email protected]")
assert preference.get_preference(ALL_MESSAGE_PREFERENCE_CATEGORY_ID) == PreferenceStatus.OPTED_OUT
+ @parameterized.expand([("project", False), ("child_environment", True)])
+ @patch("products.messaging.backend.services.customerio_import_service.SUPPRESSION_PAGE_DELAY_SECONDS", 0)
+ @patch("products.messaging.backend.services.customerio_import_service.SUPPRESSION_PAGE_SIZE", 2)
+ @patch("products.messaging.backend.services.customerio_import_service.CustomerIOClient")
+ def test_api_import_adds_customerio_suppressions(
+ self, _name: str, from_child_environment: bool, mock_client_class: MagicMock
+ ) -> None:
+ import_team_id = self.team.id
+ if from_child_environment:
+ import_team_id = Team.objects.create(
+ organization=self.organization, project=self.project, parent_team=self.team
+ ).id
+ MessageSuppression.objects.for_team(self.team.id).create(
+ team=self.team, identifier="[email protected]", source=SuppressionSource.MANUAL, suppressed=True
+ )
+ MessageSuppression.objects.for_team(self.team.id).create(
+ team=self.team, identifier="[email protected]", suppressed=False, deleted=True
+ )
+ pages = {
+ ("bounces", 0): [{"email": " [email protected] "}, {"email": "[email protected]"}],
+ ("bounces", 2): [{"email": "[email protected]"}],
+ ("spam_reports", 0): [{"email": "[email protected]"}],
+ }
+
+ def get_suppressions(suppression_type: str, limit: int, offset: int) -> list[dict]:
+ if suppression_type == "invalid_emails":
+ raise CustomerIOAPIError("Customer.io API error: 500")
+ return pages.get((suppression_type, offset), [])
+
+ mock_client = mock_client_class.return_value
+ mock_client.validate_credentials.return_value = True
+ mock_client.get_subscription_topics.return_value = []
+ mock_client.get_globally_unsubscribed_customers.return_value = {"identifiers": []}
+ mock_client.get_suppressions.side_effect = get_suppressions
+
+ result = CustomerIOImportService(import_team_id, self.api_key, self.user.id).import_api_data()
+
+ assert result["status"] == "completed"
+ assert result["suppressions_imported"] == 2
+ assert any("invalid_emails" in error for error in result["errors"])
+ rows = {
+ row.identifier: (row.source, row.suppressed, row.deleted)
+ for row in MessageSuppression.objects.for_team(self.team.id).all()
+ }
+ assert rows == {
+ "[email protected]": (SuppressionSource.BOUNCE, True, False),
+ "[email protected]": (SuppressionSource.COMPLAINT, True, False),
+ "[email protected]": (SuppressionSource.MANUAL, True, False),
+ "[email protected]": (SuppressionSource.BOUNCE, False, True),
+ }
+
def test_process_csv_without_categories(self):
"""Test CSV processing when no categories exist"""
csv_content = """email,id,cio_subscription_preferences
diff --git a/products/workflows/frontend/OptOuts/CustomerIOImportModal.stories.tsx b/products/workflows/frontend/OptOuts/CustomerIOImportModal.stories.tsx
index 0c2907847593..da3e7a33a7dd 100644
--- a/products/workflows/frontend/OptOuts/CustomerIOImportModal.stories.tsx
+++ b/products/workflows/frontend/OptOuts/CustomerIOImportModal.stories.tsx
@@ -45,6 +45,7 @@ const step1CompletedConfig: OptOutSyncConfigResponse = {
imported_at: '2026-04-13T10:00:00Z',
categories_created: 6,
globally_unsubscribed_count: 1234,
+ suppressions_imported: 2045,
},
}
diff --git a/products/workflows/frontend/OptOuts/CustomerIOImportModal.tsx b/products/workflows/frontend/OptOuts/CustomerIOImportModal.tsx
index 8e9a38b863b8..dca3a8781333 100644
--- a/products/workflows/frontend/OptOuts/CustomerIOImportModal.tsx
+++ b/products/workflows/frontend/OptOuts/CustomerIOImportModal.tsx
@@ -43,6 +43,7 @@ function Step1Content(): JSX.Element {
// Prefer local reducer state, fall back to DB-persisted result
const displayResult = importProgress?.status === 'completed' ? importProgress : null
const persistedResult = !displayResult && result?.status === 'completed' ? result : null
+ const partialErrors = displayResult?.errors ?? persistedResult?.errors ?? []
if (isImporting) {
return (
@@ -74,6 +75,11 @@ function Step1Content(): JSX.Element {
<LemonBanner type="success">
<span className="font-semibold">API import complete</span>
</LemonBanner>
+ {partialErrors.length > 0 && (
+ <LemonBanner type="warning">
+ Some data didn't import. Run the import again to retry. {partialErrors.join(', ')}
+ </LemonBanner>
+ )}
<div className="space-y-2 text-sm">
{(persistedResult?.imported_at || displayResult) && (
<div className="flex items-center justify-between">
@@ -97,6 +103,16 @@ function Step1Content(): JSX.Element {
).toLocaleString()}
</LemonTag>
</div>
+ <div className="flex items-center justify-between">
+ <span>Suppressed addresses:</span>
+ <LemonTag>
+ {(
+ displayResult?.suppressions_imported ??
+ persistedResult?.suppressions_imported ??
+ 0
+ ).toLocaleString()}
+ </LemonTag>
+ </div>
</div>
</>
)}
@@ -554,7 +570,7 @@ export function CustomerIOImportModal(): JSX.Element {
return (
<LemonModal
title="Customer.io integration"
- description="Import categories and unsubscribed users from Customer.io."
+ description="Import categories, unsubscribed users and suppressed addresses from Customer.io."
isOpen={isImportModalOpen}
onClose={closeImportModal}
width={640}
@@ -585,7 +601,7 @@ export function CustomerIOImportModal(): JSX.Element {
key: 'step1',
header: (
<div className="flex items-center justify-between w-full">
- <span>1. Import categories & global opt-outs</span>
+ <span>1. Import categories, opt-outs & suppressions</span>
<StepBadge status={stepCompletion.step1} />
</div>
),
diff --git a/products/workflows/frontend/OptOuts/customerIOImportLogic.ts b/products/workflows/frontend/OptOuts/customerIOImportLogic.ts
index 2502f33f4160..2489fc8f2be8 100644
--- a/products/workflows/frontend/OptOuts/customerIOImportLogic.ts
+++ b/products/workflows/frontend/OptOuts/customerIOImportLogic.ts
@@ -20,6 +20,7 @@ export interface ImportProgress {
topics_found: number
categories_created?: number
globally_unsubscribed_count?: number
+ suppressions_imported?: number
details?: string
errors: string[]
}
@@ -46,6 +47,8 @@ export interface AppImportResult {
imported_at: string
categories_created?: number
globally_unsubscribed_count?: number
+ suppressions_imported?: number
+ errors?: string[]
error?: string
}