Table of Contents
Managing user accounts in Google Workspace is a critical responsibility for Google admins, ensuring that employees have the right access to tools and data while maintaining security and compliance. Basic tasks around user management include creating new user accounts, updating user information, handling password resets and more. Admins also need to assign users to specific organizational units, which control access to various Google Workspace services, and manage group memberships to streamline communication and collaboration.
These tasks can become time-consuming and complex, especially as organizations grow. Google’s Directory API provides a traditional programmatic approach to managing these tasks. Let’s see how to perform them using Directory API, as well as less time consuming alternative, the #1 Google admin tasks automation tool — Zenphi.
Create a user account
Create a user account using Google Directory SDK
You can add a user account to any of your Google Workspace account’s domains. Before adding a user account, you have to confirm the domain ownership.
Use the following POST request to create an account. For the request query string properties, see the users.insert() method.
POST https://admin.googleapis.com/admin/directory/v1/users
All created requests require you to submit the information needed to fulfill the request. If you are using client libraries, they convert the data objects from your chosen language into JSON data formatted objects.
If your query rate for creation requests is too high, you might receive HTTP 503 responses from the API server indicating that your quota has been exceeded. If you get these responses, use an exponential back-off algorithm to retry your requests.
{ "primaryEmail": "liz@example.com", "name": { "givenName": "Elizabeth", "familyName": "Smith" }, "suspended": false, "password": "new user password", "hashFunction": "SHA-1", "changePasswordAtNextLogin": false, "ipWhitelisted": false, "ims": [ { "type": "work", "protocol": "gtalk", "im": "liz_im@talk.example.com", "primary": true } ], "emails": [ { "address": "liz@example.com", "type": "home", "customType": "", "primary": true } ], "addresses": [ { "type": "work", "customType": "", "streetAddress": "1600 Amphitheatre Parkway", "locality": "Mountain View", "region": "CA", "postalCode": "94043" } ], "externalIds": [ { "value": "12345", "type": "custom", "customType": "employee" } ], "organizations": [ { "name": "Google Inc.", "title": "SWE", "primary": true, "type": "work", "description": "Software engineer" } ], "phones": [ { "value": "+1 nnn nnn nnnn", "type": "work" } ], "orgUnitPath": "/corp/engineering", "includeInGlobalAddressList": true }
Create a user account with Zenphi
Simply drag and drop ‘Create User’ action choosing it from in Zenphi’s Google Admin Actions space. As the whole procedure takes less than a minute, you can easily use your time to integrate this action in proper automated workflows — something that you probably was planning to do long ago but didn’t have the bandwidth.
For example, you can use this action as a part of an employee onboarding workflow where all other actions in User management are also automated: like extracting data about new employee department, assigning them relevant access, generating passwords, as well as notifying HR and employee that the onboarding process has been completed.
As you can see by the list of outputs, the settings can be very detailed and elaborate — including assigning a User to a specific Organizational unit as a part of your user access control workflows when you configure your role-based access approvals automation in Google Workspace.
For the Organizational Units Management automations check out our short tutorials:
Update a user account
Update User Account using Google Directory SDK
To update a user account using Google Directory API, use the following PUT request and include the authorization described in Authorize requests. The userKey can be the user’s primary email address, the unique user id, or one of the user’s alias email addresses.
PUT https://admin.googleapis.com/admin/directory/v1/users/userKey
Both the request and response body contain an instance of User. However, the Directory API supports patch semantics, so you only need to submit the updated fields in your request.
Update a user account using Zenphi
With Zenphi, updating user as a part of your workflow is just one-step action.
As you can see from the visual listing the outputs, there’s a long list of variables you can update using this action. The best part, is that all the updates will be recorded in the logs for compliance and audit log purposes, automating your security and eliminating the risks of data leaks in Google Workspace.
Make a user an administrator
Make user an administrator via Google Directory SDK
To make user into a super administrator, use the following POST request and include the authorization described in Authorize requests. The userKey can be the user’s primary email address, the unique user id, or one of the user’s alias email addresses. For the request and response properties, see API Reference. For more information about a super administrator, see the administration help center.
POST https://admin.googleapis.com/admin/directory/v1/users/userKey/makeAdmin
In this example, user whose userKey is liz@example.com has become a super administrator:
POST https://admin.googleapis.com/admin/directory/v1/users/liz@example.com/makeAdmin
{ "status": true }
A successful response returns an HTTP 200 status code.
Make user an administrator via Zenphi
In Zenphi, as you can see, the action is called Convert user to Admin — this allows to assign a superadmin role to anyone in your organization in just one step without a single line of code.
Retrieve a user
Retrieve a User via Google Directory API request
To retrieve a user, use the following GET request and include the authorization described in Authorize requests. The userKey can be the user’s primary email address, the unique user id, or one of the user’s alias email addresses. For the request and response properties, see the API Reference.
This example returns the user account properties for the user whose primary or alias email address is liz@example.com:
GET https://admin.googleapis.com/admin/directory/v1/users/userKey
{ "kind": "directory#user", "id": "the unique user id", "primaryEmail": "liz@example.com", "name": { "givenName": "Liz", "familyName": "Smith", "fullName": "Liz Smith" }, "isAdmin": true, "isDelegatedAdmin": false, "lastLoginTime": "2013-02-05T10:30:03.325Z", "creationTime": "2010-04-05T17:30:04.325Z", "agreedToTerms": true, "hashFunction": "SHA-1", "suspended": false, "changePasswordAtNextLogin": false, "ipWhitelisted": false, "ims": [ { "type": "work", "protocol": "gtalk", "im": "lizim@talk.example.com", "primary": true } ], "emails": [ { "address": "liz@example.com", "type": "home", "customType": "", "primary": true } ], "addresses": [ { "type": "work", "customType": "", "streetAddress": "1600 Amphitheatre Parkway", "locality": "Mountain View", "region": "CA", "postalCode": "94043" } ], "externalIds": [ { "value": "employee number", "type": "custom", "customType": "office" } ], "organizations": [ { "name": "Google Inc.", "title": "SWE", "primary": true, "customType": "", "description": "Software engineer" } ], "phones": [ { "value": "+1 nnn nnn nnnn", "type": "work" } ], "aliases": [ "lizsmith@example.com", "lsmith@example.com" ], "nonEditableAliases": [ "liz@test.com" ], "customerId": "C03az79cb", "orgUnitPath": "corp/engineering", "isMailboxSetup": true, "includeInGlobalAddressList": true }
A successful response returns an HTTP 200 status code. Along with the status code, the response returns the properties for the user account.
Retrieve a User in Zenphi
In Zenphi an action you can use to achieve similar results and more is called ‘Lookup User’.
It’s very easy to set it up as a part of your Google admin tasks automation flow.
As you can see on the picture below, Zenphi will return you not just the user’s alias but much more:
- if it’s an Admin,
- if it was suspended,
- if it was deleted,
- time of the deletion,
- when the user logged in last time in your Google Workspace and so many more.
Using some of these variables, you can build a super efficient workflow that would allow you to optimize the cost of Google Workspace and save on the licenses. Using others, you can automate User Access Controls In Google Workspace and deprovision users efficiently by revoking access for departing employees.
We’ve already helped hundreds of companies to automate IT Operations and Google Workspace Admin tasks. Book a call to learn the best practices from your peers and listen to their honest opinion on Zenphi.
Delete a user account
Delete a user account using Google Directory API
To delete a user account, use the following DELETE request and include the authorization described in Authorize requests. The userKey can be the user’s primary email address, the unique user id, or one of the user’s alias email addresses. For the request and response properties, see the API Reference.
DELETE https://admin.googleapis.com/admin/directory/v1/users/userKey
A successful response only returns an HTTP 200 status code.
The deleted user will no longer be able to log in.
For more information about user account deletion, please refer to the administration help center.
Delete user account using Zenphi
Deleting user in Zenphi can’t be easier. The action carries the same name as it has in Google Directory — Delete user — and requires an identifier (Email or user ID).
The best part, as always, you can use this step as a part of the smooth workflow that would eliminate manual intervention and save your time as Google admin — for example, to revoke access for departing users, or to save on Google Workspace licenses while adhering to industry compliance standards.
Undelete a user account
Undelete a user account with Google Directory SDK
According to Google Directory limitations, a user deleted in the last 20 days must meet certain conditions before the user’s account can be restored.
To undelete a user account, use the following POST request and include the authorization described in Authorize requests. The userKey is the unique user id found in the response of the Retrieve users deleted within the past 20 days operation. The user’s primary email address or one of the user’s alias email addresses cannot be used in the userKey for this operation. For the request and response properties, see the API Reference.
POST https://admin.googleapis.com/admin/directory/v1/users/12309329403209438205/undelete
In this example, the user, liz@example.com, is undeleted. All of this user’s previous account properties are restored.
A successful response only returns an HTTP 204 status code. To see the undeleted user’s account, use the Retrieve a user operation.
Undelete a user account using Zenphi
With Zenphi, it’s also a one API call (‘Undelete User’ action) that allows you to restore a user account in the same or a different organizational unit.
To learn more about Google Directory actions in Zenphi contact our support team or sign up for a free trial and experience the power of Zenphi workflow automations for Google Workspace yourself.