The main issue you are having is that you are using JavaScript. Client side JavaScript does not have the ability to store login information for future use. Which means that every time your users return they will need to login and authorize your application again.

I would suggest that you switch to a server sided language which will allow your users to login and for you to store a refresh token for them enabling you to request a new access token when ever you need to. node.js for example would work as well.

Remember though only users who have admin access on your workspace account are going to be able to do this the user will need to have access

Node.js Quickstart

The following is a quick example for node.js, its for an installed app but will show you how things need to be put together for refreshing your access token.

// npm install googleapis@105 @google-cloud/[email protected] --save
// npm install googleapis

const fs = require('fs');
const path = require('path');
const process = require('process');
const {authenticate} = require('@google-cloud/local-auth');
const {google} = require('googleapis');

// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/admin.directory.user.readonly'];

// Token File Name
const TOKEN_FILE = 'token.json'

// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
const TOKEN_PATH = path.join(process.cwd(), TOKEN_FILE);
const CREDENTIALS_PATH = 'C:\\Development\\FreeLance\\GoogleSamples\\Credentials\\Workspace-Installed-TestEverything.json';
// the workspace customer id found in admin on Google Workspace
const WORKSPACE_CUSTOMER_ID = '[REDACTED]'

/**
 * Reads previously authorized credentials from the save file.
 *
 * @return {Promise<OAuth2Client|null>}
 */
async function loadSavedCredentialsIfExist() {
    try {
        const content = fs.readFileSync(TOKEN_PATH,{encoding:'utf8', flag:'r'});
        const credentials = JSON.parse(content);
        return google.auth.fromJSON(credentials);
    } catch (err) {
        return null;
    }
}

/**
 * Serializes credentials to a file compatible with GoogleAUth.fromJSON.
 *
 * @param {OAuth2Client} client
 * @return {Promise<void>}
 */
async function saveCredentials(client) {

    const content = fs.readFileSync(CREDENTIALS_PATH, {encoding:'utf8', flag:'r'});
    const keys = JSON.parse(content);

    const key = keys.installed || keys.web;
    const payload = JSON.stringify({
        type: 'authorized_user',
        client_id: key.client_id,
        client_secret: key.client_secret,
        refresh_token: client.credentials.refresh_token,
    });
    await fs.writeFileSync(TOKEN_PATH, payload);
}

/**
 * Load or request or authorization to call APIs.
 *
 */
async function authorize() {
    let client = await loadSavedCredentialsIfExist();
    if (client) {
        return client;
    }
    client = await authenticate({
        scopes: SCOPES,
        keyfilePath: CREDENTIALS_PATH,
    });
    if (client.credentials) {
        await saveCredentials(client);
    }
    return client;
}

/**
 * Lists the names and IDs of up to ten users on Google Workspace.
 * @param {OAuth2Client} authClient An authorized OAuth2 client.
 */
async function listUsers(authClient) {
    const service = google.admin({version: 'directory_v1', auth: authClient});
    const res = await service.users.list({
        customer: WORKSPACE_CUSTOMER_ID,
        pageSize: 10,
        fields: 'nextPageToken, users(id, name)',
    });

    const users = res.data.users;
    if (users.length === 0) {
        console.log('No users found.');
        return;
    }

    console.log('users:');
    users.map((user) => {
        console.log(`${user.name.fullName} (${user.id})`);
    });
}

authorize().then(listUsers).catch(console.error);

Google workspace

In google workspace under the user, You can check if they have admin access.

Answer from Linda Lawton - DaImTo on Stack Overflow
🌐
Exclaimer
support.exclaimer.com › hc › en-gb › articles › 6792817410333-How-to-use-the-Google-Directory-API-to-query-Google-Directory-for-User-Data
How to use the Google Directory API to query Google Directory for User Data – Exclaimer Knowledge Base
November 11, 2024 - To complete the steps described below, you will need: Google Workspace Administrator credentials with either of the following scopes: - Global scope for access to all user and user alias operations. - Scope for only retrieving users or user aliases · Browse to the G Suite Admin SDK - Directory API site (https://developers.google.com/admin-sdk/directory/v1/reference/users/get).
🌐
Google
discuss.google.dev › google workspace developers › q&a
Google Directory API - Service acount with Domain-wide delegation - Q&A - Google Developer forums
August 26, 2024 - Hello everyone! I’m trying to connect to the Google Directory API (REST Resource: users) via Airflow. I want to get a list of users within the organizational google workspace as well as update some attributes. I want to do this programmatically via the service account that has been setup within the API project with appropriate scope: https://www.googleapis.com/auth/admin.directory.user.
Discussions

Google API to list users in directory
I am developing a user page to allow managers to create users by selecting a new user from a drop down list. I will like to populate the drop down with company users from Google directory. So this ... More on stackoverflow.com
🌐 stackoverflow.com
Lessons learned using the Google Directory API Ruby client (x post from /r/google)
2 votes and 0 comments so far on Reddit More on reddit.com
🌐 r/ruby
2
Perl for Google Admin SDK Directory API?
I was wondering if anybody knows ... SDK's Directory API? I have some account management scripts that rely on the Google Apps Provisioning API (via VUser::Google::ProvisioningAPI) but they're cutting off access to that API in a couple months. ... Be the first to share what you think! ... Reddit Inc © ... More on reddit.com
🌐 r/perl
3
How much to use Google Maps API (specifically the "Places (new)" API) to populate my directory?

Use the pricing calculator. https://mapsplatform.google.com/pricing/

You will have to build your caching layer, and can use whatever backend you like, including MongoDB or Redis. Don’t forget to expire cache entries so that you periodically fetch updated data.

More on reddit.com
🌐 r/googlecloud
2
3
January 12, 2024
🌐
Google Support
support.google.com › a › answer › 10427204
Create and manage groups using APIs - Google Workspace Admin Help
Groups you create using an API receive specific default settings. Use the Google Workspace Admin SDK’s Directory API to create, update, or delete a group and its membership. Complete tasks such as changing the group name, assigning a group email alias, and adding or removing members.
🌐
Google Groups
groups.google.com › g › google-api-php-client › c › LM-mwmuZe7I
Google Admin SDK Directory Service API Implementation (see attachment)
The reason why Directory Service was not included before is a, well, a bug in my scripts :D ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... I've just found out that we have actually released that code. You can find it in this project: https://code.google.com/p/google-apis-client-generator/
🌐
Withgoogle
workspace-api-explorer.withgoogle.com
Try Google Workspace APIs
We cannot provide a description for this page right now
🌐
Query Docs
docs.query.ai › docs › google-workspace-directory-api
Federated Search for the Google Workspace Directory API
The document provides a step-by-step guide for integrating Google Workspace with Query, detailing the activation of necessary APIs, creation of a Service Account, retrieval of Customer ID, and configuration of a Directory API Connector to enable federated searches for user and device information, primarily for security and IT operations.
Find elsewhere
Top answer
1 of 1
1

The main issue you are having is that you are using JavaScript. Client side JavaScript does not have the ability to store login information for future use. Which means that every time your users return they will need to login and authorize your application again.

I would suggest that you switch to a server sided language which will allow your users to login and for you to store a refresh token for them enabling you to request a new access token when ever you need to. node.js for example would work as well.

Remember though only users who have admin access on your workspace account are going to be able to do this the user will need to have access

Node.js Quickstart

The following is a quick example for node.js, its for an installed app but will show you how things need to be put together for refreshing your access token.

// npm install googleapis@105 @google-cloud/[email protected] --save
// npm install googleapis

const fs = require('fs');
const path = require('path');
const process = require('process');
const {authenticate} = require('@google-cloud/local-auth');
const {google} = require('googleapis');

// If modifying these scopes, delete token.json.
const SCOPES = ['https://www.googleapis.com/auth/admin.directory.user.readonly'];

// Token File Name
const TOKEN_FILE = 'token.json'

// The file token.json stores the user's access and refresh tokens, and is
// created automatically when the authorization flow completes for the first
// time.
const TOKEN_PATH = path.join(process.cwd(), TOKEN_FILE);
const CREDENTIALS_PATH = 'C:\\Development\\FreeLance\\GoogleSamples\\Credentials\\Workspace-Installed-TestEverything.json';
// the workspace customer id found in admin on Google Workspace
const WORKSPACE_CUSTOMER_ID = '[REDACTED]'

/**
 * Reads previously authorized credentials from the save file.
 *
 * @return {Promise<OAuth2Client|null>}
 */
async function loadSavedCredentialsIfExist() {
    try {
        const content = fs.readFileSync(TOKEN_PATH,{encoding:'utf8', flag:'r'});
        const credentials = JSON.parse(content);
        return google.auth.fromJSON(credentials);
    } catch (err) {
        return null;
    }
}

/**
 * Serializes credentials to a file compatible with GoogleAUth.fromJSON.
 *
 * @param {OAuth2Client} client
 * @return {Promise<void>}
 */
async function saveCredentials(client) {

    const content = fs.readFileSync(CREDENTIALS_PATH, {encoding:'utf8', flag:'r'});
    const keys = JSON.parse(content);

    const key = keys.installed || keys.web;
    const payload = JSON.stringify({
        type: 'authorized_user',
        client_id: key.client_id,
        client_secret: key.client_secret,
        refresh_token: client.credentials.refresh_token,
    });
    await fs.writeFileSync(TOKEN_PATH, payload);
}

/**
 * Load or request or authorization to call APIs.
 *
 */
async function authorize() {
    let client = await loadSavedCredentialsIfExist();
    if (client) {
        return client;
    }
    client = await authenticate({
        scopes: SCOPES,
        keyfilePath: CREDENTIALS_PATH,
    });
    if (client.credentials) {
        await saveCredentials(client);
    }
    return client;
}

/**
 * Lists the names and IDs of up to ten users on Google Workspace.
 * @param {OAuth2Client} authClient An authorized OAuth2 client.
 */
async function listUsers(authClient) {
    const service = google.admin({version: 'directory_v1', auth: authClient});
    const res = await service.users.list({
        customer: WORKSPACE_CUSTOMER_ID,
        pageSize: 10,
        fields: 'nextPageToken, users(id, name)',
    });

    const users = res.data.users;
    if (users.length === 0) {
        console.log('No users found.');
        return;
    }

    console.log('users:');
    users.map((user) => {
        console.log(`${user.name.fullName} (${user.id})`);
    });
}

authorize().then(listUsers).catch(console.error);

Google workspace

In google workspace under the user, You can check if they have admin access.

🌐
Javadoc.io
javadoc.io › doc › com.google.apis › google-api-services-admin-directory › latest › index.html
google-api-services-admin-directory directory_v1-rev20250804-2.0.0 javadoc (com.google.apis)
Latest version of com.google.apis:google-api-services-admin-directory · https://javadoc.io/doc/com.google.apis/google-api-services-admin-directory · Current version directory_v1-rev20250804-2.0.0 · https://javadoc.io/doc/com.google.apis/google-api-services-admin-directory/directory_v1-rev20250804-2.0.0 ·
🌐
DEV Community
dev.to › osinachiuro › implement-admin-sdk-directory-api-for-google-workspace-management-37nd
Implement Admin SDK Directory API for Google Workspace Management - DEV Community
February 13, 2025 - The Admin SDK Directory API allows enterprise domain administrators to view and manage their organization's users, groups, devices, and resources. To Develop on Google Workspace particularly using the Admin SDK API the following has to be set up:
🌐
Google
developers.google.com › google workspace › admin console › directory api overview
Directory API Overview | Admin console | Google for Developers
October 13, 2025 - The Directory API is part of the RESTful Admin SDK API that can be used to programmatically create and manage admin-controlled resources owned by a Google Workspace account.
🌐
Google Cloud
console.cloud.google.com › apis › library › admin.googleapis.com
Admin SDK API – APIs and services
Google Cloud Console has failed to load JavaScript sources from www.gstatic.com. Possible reasons are:www.gstatic.com or its IP addresses are blocked by your network administratorGoogle has temporarily blocked your account or network due to excessive automated requestsPlease contact your network ...
🌐
Google
developers.google.com › google workspace › admin console › admin sdk: directory api
Admin SDK: Directory API | Admin console | Google for Developers
The Admin SDK Directory API lets administrators of enterprise domains view and manage their organization's users, groups, devices, and related resources. The Cloud Identity APIs offer additional ways of managing some of the same resources.
🌐
Bindbee
bindbee.dev › blog › google-workspace-api
How to Use Google Workspace API: Step-by-Step Guide+ Code
April 11, 2025 - The Google Workspace Directory API enables administrators to programmatically manage user accounts, relationships, and organizational data within a Google Workspace domain.
🌐
Google Cloud
cloud.google.com › find-a-partner
Find a Partner - Partner Directory
Meet your business challenges head on with cloud computing services from Google, including data management, hybrid & multi-cloud, and AI & ML.
🌐
Google Toolbox
toolbox.googleapps.com › apps › main
Google Admin Toolbox
Log Analyzer enables you you to analyze log files generated by Google products, including Chrome, Google Workspace Sync for Microsoft Outlook, and Google Cloud Directory Sync.
🌐
Google Cloud
cloud.google.com › apis
Cloud APIs | Google Cloud
Network Management API · Provides a collection of network performance monitoring and diagnostic capabilities. Serverless VPC Access · Manage VPC access connectors. Service Directory API · Discover, publish and connect services. Service Networking API · Provides automatic management of network configurations necessary for certain services.
🌐
GitHub
github.com › public-apis › public-apis
GitHub - public-apis/public-apis: A collective list of free APIs
A collective list of free APIs. Contribute to public-apis/public-apis development by creating an account on GitHub.
Starred by 387K users
Forked by 41.3K users
Languages   Python 96.8% | Shell 3.2%
🌐
Google
developers.google.com › google workspace › admin console › directory api: client libraries
Directory API: Client Libraries | Admin console | Google for Developers
October 13, 2025 - The Directory API is built on HTTP and JSON, so any standard HTTP client can send requests to it and parse the responses. However, the Google APIs client libraries provide better language integration, improved security, and support for making ...
🌐
Google Cloud
cloud.google.com › service directory › documentation › service directory api
Service Directory API | Google Cloud
June 27, 2025 - Service Directory is a platform for discovering, publishing, and connecting services. ... To call this service, we recommend that you use the Google-provided client libraries. If your application needs to use your own libraries to call this ...