{"record":{"id":"0b0aa6d230024b33","repo":"getredash/redash","slug":"failed-getting-accounts","errorCode":null,"errorMessage":"Failed getting accounts.","messagePattern":"Failed getting accounts\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/google_analytics.py","lineNumber":131,"sourceCode":"    def __init__(self, configuration):\n        super(GoogleAnalytics, self).__init__(configuration)\n        self.syntax = \"json\"\n\n    def _get_analytics_service(self):\n        scopes = [\"https://www.googleapis.com/auth/analytics.readonly\"]\n\n        try:\n            key = json_loads(b64decode(self.configuration[\"jsonKeyFile\"]))\n            creds = Credentials.from_service_account_info(key, scopes=scopes)\n        except KeyError:\n            creds = google.auth.default(scopes=scopes)[0]\n\n        return build(\"analytics\", \"v3\", credentials=creds)\n\n    def _get_tables(self, schema):\n        accounts = self._get_analytics_service().management().accounts().list().execute().get(\"items\")\n        if accounts is None:\n            raise Exception(\"Failed getting accounts.\")\n        else:\n            for account in accounts:\n                schema[account[\"name\"]] = {\"name\": account[\"name\"], \"columns\": []}\n                properties = (\n                    self._get_analytics_service()\n                    .management()\n                    .webproperties()\n                    .list(accountId=account[\"id\"])\n                    .execute()\n                    .get(\"items\", [])\n                )\n                for property_ in properties:\n                    if \"defaultProfileId\" in property_ and \"name\" in property_:\n                        schema[account[\"name\"]][\"columns\"].append(\n                            \"{0} (ga:{1})\".format(property_[\"name\"], property_[\"defaultProfileId\"])\n                        )\n\n        return list(schema.values())","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/google_analytics.py#L113-L149","documentation":"During schema discovery (_get_tables), the runner calls the GA Management API accounts().list(); if the response has no 'items' key it raises 'Failed getting accounts.' — meaning the API returned an empty or unexpected payload, commonly because authentication lacks access to any account or the API is disabled.","triggerScenarios":"test_connection / schema load when the service account or OAuth user has no GA accounts, the Analytics API is not enabled for the project, or scopes are insufficient so list() returns an error dict without items.","commonSituations":"Missing google-analytics.readonly scope, Analytics API disabled in GCP console, service account email not added to any GA account, quota/project mixups.","solutions":["Confirm the service account user (or OAuth user) has at least Reader access on a GA account and its email is invited in GA Admin","Enable the Google Analytics API for the GCP project and use the correct credentials JSON","Verify scopes include https://www.googleapis.com/auth/analytics.readonly","Call the Management API directly (accounts().list()) with the same creds to see the raw response"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    runner.get_schema(scope)\nexcept Exception as e:\n    if \"Failed getting accounts\" in str(e):\n        alert_admin_to_check_ga_access_and_api_enablement()","preventionTips":["Grant the service account Reader access on a GA account before adding the data source","Enable the Analytics API in the GCP project","Verify credentials JSON and scopes (analytics.readonly) during setup"],"tags":["google-analytics","authentication","schema","permissions"],"backgroundTag":"api-permission-denied","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}