title: How do I fix the 403:insufficient authentication scopes error from Google Analytics User Deletion API
body: <p>Getting the below error while calling the Google Analytics <a href="https://developers.google.com/analytics/devguides/config/userdeletion/v3/reference/userDeletion/userDeletionRequest/upsert" rel="nofollow noreferrer">user deletion API</a> </p>
  
  <p><strong>Error</strong></p>
  
  <blockquote>
    <p>HttpError: https://www.googleapis.com/analytics/v3/management/accounts/5795821/entityUserLinks/%27785972698.1540375322%27? returned "Insufficient Permission: Request had insufficient authentication scopes."></p>
  </blockquote>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import csv
  from apiclient.discovery import build
  from oauth2client.service_account import ServiceAccountCredentials
  
  
  def get_service(api_name, api_version, scope, key_file_location):
      credentials = ServiceAccountCredentials.from_json_keyfile_name(key_file_location,scope)      
      #Build the service object.
      service = build(api_name, api_version, credentials=credentials)
      return service
  
  
  # open a list of client ids
  with open('File_name.csv', 'rt') as csvfile:
      reader = csv.reader(csvfile, dialect='excel')
      reader_list = list(reader)
  
  def delete_users(service):
      for row in reader_list:
          for row in reader_list:
              service.management().accountUserLinks().delete(
              accountId ='XXXXXX', 
              linkId = row[0]
              ).execute()
  
  def main():
      # Define the auth scopes to request.
      scope = ['https://www.googleapis.com/auth/analytics.user.deletion']
      key_file_location = 'credentials.json'
  
      # Authenticate and construct service.
      service = get_service('analytics', 'v3', scope, key_file_location)
      delete_users(service)
  
  
  if __name__ == '__main__':
      main()
  
  </code></pre>
  
  <p>I have downloaded the credentials file from GCP console >  Service accounts and using the same. Not able to understand what the exact cause is and how to resolve it. Where can I see/define the authentication scopes ? Any documentation or help would be appreciated.</p>
  
  <p>I even tried sending ViewId in-place of accountId as per <a href="https://stackoverflow.com/questions/23128964/google-analytics-reports-api-insufficient-permission-403">this post</a> but same error.</p>
  
  <p>Really disappointed with the google documentation for the same.</p>