Reputation: 41
I am trying to get all users from google workspace using python but I am getting this error message as a response " "exception": "googleapiclient.errors.HttpError: <HttpError 400 when requesting https://admin.googleapis.com/admin/directory/v1/users?customer=my_customer&query=isSuspended%3DFalse&maxResults=100&orderBy=email&viewType=admin_view&projection=basic&showDeleted=False&alt=json returned "Invalid Input". Details: "[{'message': 'Invalid Input', 'domain': 'global', 'reason': 'invalid'}]">" ".Below is my code;
import frappe
import json
from google.oauth2 import service_account
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/admin.directory.user.readonly']
SUBJECT = 'workspace_email'
CUSTOMER_ID = 'my_customer'
@frappe.whitelist(allow_guest=True)
def main():
credentials = service_account.Credentials.from_service_account_file(
'path_to_my_config.json', scopes=SCOPES
)
credentials = credentials.with_subject(SUBJECT)
admin = build('admin', 'directory_v1', credentials=credentials)
results = admin.users().list(
customer=CUSTOMER_ID,
query='isSuspended=False',
maxResults=100,
orderBy='email',
viewType='admin_view',
projection='basic',
showDeleted=False,
).execute()
print(json.dumps(results, indent=4))
if __name__ == '__main__':
main()
I have tried regenerating a new service key and assigning the following roles to my principal i.e " Owner, Service Account Admin, Service Account Token Creator, Service Account User "
Is there something I'm missing or not doing correct?
Upvotes: 0
Views: 179
Reputation: 1
yo must change viewType='admin_view' to viewType='domain_public' https://developers.google.com/admin-sdk/directory/v1/guides/manage-users?hl=es-419#retrieve_users_non_admin
Upvotes: 0