Search code examples
pythongoogle-apigoogle-admin-sdkgoogle-workspacegoogle-api-python-client

makeAdmin google API Gsuite SDK errors


I'm following this article to make a user an Admin for gsuite: https://developers.google.com/admin-sdk/directory/v1/reference/users/makeAdmin

I'm using python to do so and my code is:

        SCOPES = ['https://www.googleapis.com/auth/admin.directory.user', 'https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/spreadsheets']
        SERVICE_ACCOUNT_FILE = 'SA.json'

        credentials = service_account.Credentials.from_service_account_file(
            SERVICE_ACCOUNT_FILE, scopes=SCOPES)

        self.delegated_credentials = credentials.with_subject('[email protected]')

        self.service = googleapiclient.discovery.build('admin', 'directory_v1', credentials=self.delegated_credentials)
        self.service.users().makeAdmin(userKey="[email protected]").execute()

But unfortunately I get this error:

> googleapiclient.errors.HttpError: <HttpError 400 when requesting
> https://www.googleapis.com/admin/directory/v1/users/[email protected]/makeAdmin?
> returned "Missing required field: is_admin">

If I try to list users with:

users = self.service.users().list(customer='my_customer').execute()

it just works fine.

What is the parameter is_admin that the error is referring to? I can't see anything about it in the documentation.

Thanks


Solution

  • The Makeadmin method has a body paramater as welll which takes a boolean

    {
      "status": boolean
    }
    

    I think this is your missing is_admin field.

    self.service.users().makeAdmin(userKey="[email protected]", { "status": True }).execute()