Stay organized with collectionsSave and categorize content based on your preferences.
Quickstarts explain how to set up and run an app that calls a
Google Workspace API.
Google Workspace quickstarts use the API client libraries to handle some
details of the authentication and authorization flow. We recommend that
you use the client libraries for your own apps. This quickstart uses a
simplified authentication approach that is appropriate for a testing
environment. For a production environment, we recommend learning aboutauthentication and authorizationbeforechoosing the access credentialsthat are appropriate for your app.
/*** Lists users in a Google Workspace domain.* @see https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list*/functionlistUsers(){constoptionalArgs={customer:'my_customer',maxResults:10,orderBy:'email'};try{constresponse=AdminDirectory.Users.list(optionalArgs);constusers=response.users;if(!users||users.length===0){console.log('Nousersfound.');return;}// Print the list of user's full name and emailconsole.log('Users:');for(constuserofusers){console.log('%s(%s)',user.primaryEmail,user.name.fullName);}}catch(err){// TODO (developer)- Handle exception from the Directory APIconsole.log('Failedwitherror%s',err.message);}}
Click Save.
ClickUntitled project, typeQuickstart, and clickRename.
Configure the script
Enable the Directory API
Open the Apps Script project.
ClickEditorcode.
Next toServices, click Add a serviceadd.
Select
Admin Directory API
and clickAdd.
Run the sample
In the Apps Script editor, clickRun.
The first time you run the sample, it prompts you to authorize access:
ClickReview permissions.
Choose an account.
ClickAllow.
The script's execution log appears at the bottom of the window.