Learn business growth with Google Analytics 4 Forums Google Analytics 4 Understanding the permission error in Google Analytics Admin API.

  • Understanding the permission error in Google Analytics Admin API.

    Posted by Mason on 8 September 2022 at 2:06 pm

    Hey guys, I need a little help here. I’ve been trying to use the Google Analytics Admin API and keep running into a permission issue. Here’s the code I’m working with:

    `python
    import os
    from google.analytics.admin import AnalyticsAdminServiceClient

    os.environ[“GOOGLE_APPLICATION_CREDENTIALS”] = “service_account_credentials.json”

    client = AnalyticsAdminServiceClient()
    client.get_account(name=’accounts/134494883′)
    `

    But all I get is a PermissionDenied: 403 The caller does not have permission error.

    The odd thing is, I downloaded service account credentials as a key and it has full owner permissions. Also, I’ve got all the APIs I need (Google Analytics Admin API, Google Analytics API, and Analytics Reporting API) up and running.

    I can see the requests are reaching the analytics admin API because I get a response, only it’s a permission error. I also used another method, client.list_accounts(), which doesn’t give an error but gives me a blank list. This is probably why the error rate is only 27%.

    What’s even weirder is I do have multiple UA and GA4 accounts under my google account. Here’s a screenshot of what I am seeing: [Link](https://i.stack.imgur.com/37B4E.png).

    Surprised emoji! Any thoughts? Would appreciate any help you can offer.

    Jackson replied 1 year, 5 months ago 3 Members · 2 Replies
  • 2 Replies
  • John

    Member
    10 May 2023 at 6:26 am

    It sounds like your service account might not have the necessary permissions within your Google Analytics account. Even though you’ve set it to have full owner permissions, you might need to go into your Google Analytics account settings and explicitly give your service account email permission to access the account. Try adding the service account email (usually in the format your-service-account@your-project-id.iam.gserviceaccount.com) as a user in your Google Analytics account with the necessary permissions and see if the issue persists.

  • Jackson

    Member
    20 June 2023 at 11:14 pm

    The PermissionDenied: 403 The caller does not have permission error occurs because the service account you’re using doesn’t have the necessary permissions. This error can occur even if you’ve assigned full owner permissions to the service account. The Google Analytics API relies on a different set of permissions which need to be assigned within the Google Analytics Admin Console.

    You need to add the service account email to the user management section in the Admin Console of the Analytics account you are trying to access. In that User Management, you’ll want to ensure you’ve provided ‘Read & Analyze’ access at a minimum and if you need to manage other aspects of the account, you may need additional permissions.

    The blank list results from client.list_accounts() also suggests that the service account doesn’t have permission to view any accounts.

    Please note that each of your Google Analytics accounts (UA or GA4) will have to be individually shared with the service account’s email for it to be able to access them via the API.

    And please ensure you have the latest Google analytics libraries installed properly. If you have previous versions you might run into compatibility issues which can cause permission issues as well.

    As you’ve mentioned you’ve multiple Google Analytics account under same google account, make sure you are trying to get data for the accounts for which your service account has proper permissions. Check that the service account key you are using is for the same project in which the Google Analytics API is enabled.

Log in to reply.