OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

I am trying to get all users from google workspace using python but I am getting a HTTP error with code 400 after making the API call

  • Thread starter Thread starter Verckys Orwa
  • Start date Start date
V

Verckys Orwa

Guest
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/...w&projection=basic&showDeleted=False&alt=json returned "Invalid Input". Details: "[{'message': 'Invalid Input', 'domain': 'global', 'reason': 'invalid'}]">" ".Below is my code;

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?
<p>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 <a href="https://admin.googleapis.com/admin/...w&projection=basic&showDeleted=False&alt=json" rel="nofollow noreferrer">https://admin.googleapis.com/admin/...w&projection=basic&showDeleted=False&alt=json</a> returned "Invalid Input". Details: "[{'message': 'Invalid Input', 'domain': 'global', 'reason': 'invalid'}]">" ".Below is my code;</p>
<pre><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()
</code></pre>
<p>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
"</p>
<p>Is there something I'm missing or not doing correct?</p>
Continue reading...
 

Latest posts

M
Replies
0
Views
1
Meliodas Dragon
M
Top