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.

fix(linkedin_ads): treat restricted member 401 as non-retryable (#64110)

Tom Owerse7c10d1975a3
diff --git a/posthog/temporal/data_imports/sources/linkedin_ads/source.py b/posthog/temporal/data_imports/sources/linkedin_ads/source.py
index 883d0cb6ca10..eb09df5db99e 100644
--- a/posthog/temporal/data_imports/sources/linkedin_ads/source.py
+++ b/posthog/temporal/data_imports/sources/linkedin_ads/source.py
@@ -51,6 +51,11 @@ class LinkedInAdsSource(ResumableSource[LinkedinAdsSourceConfig, LinkedInAdsResu
# resource can't be resolved — typically a deleted account, a wrong Account ID, or lost
# access. Retrying can't recover it, so stop syncing instead of looping the 404.
"RESOURCE_NOT_FOUND": "LinkedIn could not find the requested ad account. It may have been deleted, the configured Account ID may be wrong, or PostHog may have lost access. Check the Account ID and re-authorize the LinkedIn Ads integration.",
+ # LinkedIn returns a 401 with this stable error code when the member who authorized the
+ # integration has been restricted on LinkedIn's side (suspended / flagged account). The
+ # token can't be used until LinkedIn lifts the restriction, so retrying never recovers —
+ # stop syncing and tell the user to resolve it with LinkedIn and re-authorize.
+ "RESTRICTED_MEMBER": "LinkedIn has restricted the account that authorized this integration, so PostHog can no longer access your ad data. Resolve the restriction with LinkedIn, then re-authorize the LinkedIn Ads integration.",
# The Account ID is a free-text field. A malformed value (a profile URL, a name, stray
# whitespace) makes LinkedIn reject the `urn:li:sponsoredAccount:<id>` accounts param with
# a deterministic 400 ("...is invalid. Reason: Deserializing output ... failed"). Retrying
diff --git a/posthog/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py b/posthog/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
index 0d85162130c8..2bcc52c22dfb 100644
--- a/posthog/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
+++ b/posthog/temporal/data_imports/sources/linkedin_ads/tests/test_linkedin_source.py
@@ -23,6 +23,7 @@ class TestLinkedInAdsSource:
'LinkedIn API error (404): {"status":404,"code":"RESOURCE_NOT_FOUND","message":"No virtual resource found"}',
"REVOKED_ACCESS_TOKEN",
"The token used in the request has expired",
+ 'LinkedIn API error (401): {"status":401,"serviceErrorCode":65608,"code":"RESTRICTED_MEMBER","message":"Member is restricted"}',
],
)
def test_non_retryable_errors_match_upstream_failures(self, observed_error):