: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(warehouse): make connecting Instagram work again (#86748)
Javier Bahamondese5d0a8b4f45f
diff --git a/posthog/models/integration/oauth.py b/posthog/models/integration/oauth.pyindex e626fae3d56e..0c60adfdb328 100644--- a/posthog/models/integration/oauth.py+++ b/posthog/models/integration/oauth.py@@ -79,13 +79,12 @@ def _raise_oauth_validation_error(kind: str, res: requests.Response) -> NoReturn# Instagram API with Facebook Login: the professional account is reached through the Facebook Page-# it is linked to, so the grant needs the page permissions as well as the Instagram ones. Meta-# replaced the legacy `instagram_*` permission names with `instagram_business_*`; the old names are-# rejected at the OAuth dialog ("This app needs at least one supported permission").+# it is linked to, so the grant needs the page permissions as well as the Instagram ones. These are+# the Facebook Login permission names. The `instagram_business_*` names belong to Instagram Login, a+# separate flow with its own authorize host, so the dialog rejects them as invalid scopes here.# https://developers.facebook.com/docs/instagram-platform/instagram-api-with-facebook-loginINSTAGRAM_OAUTH_SCOPE = (- "instagram_business_basic instagram_business_manage_insights instagram_business_manage_comments"- " pages_show_list pages_read_engagement"+ "instagram_basic instagram_manage_insights instagram_manage_comments pages_show_list pages_read_engagement")diff --git a/posthog/models/test/integration/test_meta.py b/posthog/models/test/integration/test_meta.pyindex d2a50f45a7e3..75dc73c31553 100644--- a/posthog/models/test/integration/test_meta.py+++ b/posthog/models/test/integration/test_meta.py@@ -28,9 +28,9 @@ class TestInstagramIntegrationModel(BaseTest):# Instagram is reached through the Facebook page it is linked to, so the page scopes# are as load-bearing as the Instagram ones.assert set(config.scope.split(" ")) == {- "instagram_business_basic",- "instagram_business_manage_insights",- "instagram_business_manage_comments",+ "instagram_basic",+ "instagram_manage_insights",+ "instagram_manage_comments","pages_show_list","pages_read_engagement",}diff --git a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsxindex 4259c675b060..bb6694db970f 100644--- a/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx+++ b/products/data_warehouse/frontend/shared/components/forms/IntegrationAccountSelector.tsx@@ -426,8 +426,8 @@ function IntegrationAccountFieldWithDropdown({)}{accountsLoaded && !accountsLoading && !accountsError && accounts.length === 0 && (<p className="m-0 text-xs text-warning">- No accounts are accessible for this connection. Check that the connected account has the- right permissions, then <ReconnectLink integrationKind={integrationKind} />.+ No accounts to show. If you know the {fieldLabel}, enter it above and save. You can also{' '}+ <ReconnectLink integrationKind={integrationKind} /> to grant access to more accounts.</p>)}{savedValueMissing && (diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/instagram.py b/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/instagram.pyindex 3b7b5821613b..ac7d14ee87a4 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/instagram.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/instagram.py@@ -626,6 +626,11 @@ def list_professional_accounts(A page with no linked professional account is skipped rather than offered as a choice thatcan never sync.++ Accounts owned by a Business portfolio stay invisible here even when the page really is linked:+ Meta omits `instagram_business_account` rather than erroring unless the token carries+ `business_management`, which this integration deliberately does not request. Syncing such an+ account works once its ID is known, so the account field also accepts an ID typed by hand."""client = InstagramClient(access_token=access_token, api_version=api_version, logger=logger)url = client.build_url("me/accounts", {"fields": PAGE_FIELDS, "limit": str(PAGE_SIZE)})diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/tests/test_instagram_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/tests/test_instagram_source.pyindex 577e7db93290..5d94a6bde745 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/tests/test_instagram_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/instagram/tests/test_instagram_source.py@@ -96,9 +96,9 @@ class TestInstagramSource:# be able to tell the user which grant is missing.assert integration.requiredScopes is not Noneassert set(integration.requiredScopes.split(" ")) == {- "instagram_business_basic",- "instagram_business_manage_insights",- "instagram_business_manage_comments",+ "instagram_basic",+ "instagram_manage_insights",+ "instagram_manage_comments","pages_show_list","pages_read_engagement",}