Search code examples
google-apigoogle-appsgoogle-api-python-client

Retrieve all or children organization units using Google Client Library


How to retrieve all organisation units in a google apps domain using google client library ? Which function we need to use to retrive the OrgUnits in google client library ?

I didn't find any documentation on gdata-python-client site

def create_service():
    f = file(API_DATA["SERVICE_PEM_PATH"], 'rb')
    key = f.read()
    f.close()

    credentials = SignedJwtAssertionCredentials(API_DATA["SERVICE_EMAIL"], key, scope=API_DATA["DIRECTORY_SCOPES"], sub=API_DATA["ADMIN_EMAIL"])
    http = httplib2.Http()
    http = credentials.authorize(http)

    service = build("admin", "directory_v1", http=http)
    return service


directory = create_service()

# directory.RetrieveAllOrganizationUsers() -- Function to retrieve Org Units ?? 

Solution

  • There is an API method dedicated to this : orgunits.list.

    The reference documentation is here.

    The Python library documentation is here.

    I am not an expert in python, but I expect the call to look like this :

    directory.orgunits().list(customerId='my_customer').execute()
    

    By the was this is not a GData API, that's why you did not find info there. GData is the name of the old format of APIs, that Google is progressively deprecating.