# Postman API call request to deactivate the Google Workspace

**URL:** <https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883>\
**Category:** Help Hub\
**Created:** [December 21, 2023, 2:54pm UTC](https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883 "2023-12-21T14:54:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![research-engineer-62](https://avatars.discourse-cdn.com/v4/letter/r/0ea827/32.png) [@research-engineer-62](https://community.postman.com/u/research-engineer-62)\
**Post date:** [December 21, 2023, 2:54pm UTC](https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883/1 "2023-12-21T14:54:13Z")

</div>

Please help me with the step-by-step process to create a Postman API call request to deactivate the Google Workspace user account

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [December 21, 2023, 3:03pm UTC](https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883/2 "2023-12-21T15:03:23Z")

</div>

Hey @research-engineer-62 👋

Can you provide more details and context here, please.

---

<div class="post-metadata">

**Author:** ![research-engineer-62](https://avatars.discourse-cdn.com/v4/letter/r/0ea827/32.png) [@research-engineer-62](https://community.postman.com/u/research-engineer-62)\
**Post date:** [December 22, 2023, 4:25am UTC](https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883/3 "2023-12-22T04:25:04Z")

</div>

Hi @danny-dainton,

I have successfully created a Postman request for deleting a Google Workspace user, as shown in the attached screenshot below.

However, I now need assistance in modifying the Postman call to deactivate the user account instead of deleting it. Please guide how to achieve this. Thank you.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/0/4/046f88bcd12b310e9e4e77024567bd3234909685.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [December 22, 2023, 7:49am UTC](https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883/4 "2023-12-22T07:49:36Z")

</div>

Which documentation are you following?

What are the details of the request needed to deactivate a user?

Can you deactivate a user via the API? Is there a different way of doing that but changing their role of something different.

There’s no real context about why you need to do this or how this fits into something you’re working on.

---

<div class="post-metadata">

**Author:** ![research-engineer-62](https://avatars.discourse-cdn.com/v4/letter/r/0ea827/32.png) [@research-engineer-62](https://community.postman.com/u/research-engineer-62)\
**Post date:** [December 22, 2023, 3:46pm UTC](https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883/5 "2023-12-22T15:46:53Z")

</div>

I am just following online documentation.

can you please help me with the related documents?

Yes, it’s working in my Python code. but I am required in Curl code for a successful response.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [December 22, 2023, 4:17pm UTC](https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883/6 "2023-12-22T16:17:30Z")

</div>

Which documentation, you’re going to need to provide a link 😅

What does the python code look like?

---

<div class="post-metadata">

**Author:** ![research-engineer-62](https://avatars.discourse-cdn.com/v4/letter/r/0ea827/32.png) [@research-engineer-62](https://community.postman.com/u/research-engineer-62)\
**Post date:** [December 25, 2023, 7:52am UTC](https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883/7 "2023-12-25T07:52:04Z")

</div>

Hi @danny-dainton

below is the Python code, which is working for User deactivation.. I have used json file for that authentication token.

import os.path  
from google.auth.transport.requests import Request  
from google.oauth2.credentials import Credentials  
from google\_auth\_oauthlib.flow import InstalledAppFlow  
from googleapiclient.discovery import build

# If modifying these scopes, delete the file token.json.

SCOPES = [“[https://www.googleapis.com/auth/admin.directory.user](https://www.googleapis.com/auth/admin.directory.user)”]

def main():

```
creds = None
# 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.
if os.path.exists("token.json"):
    creds = Credentials.from_authorized_user_file("token.json", SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
    if creds and creds.expired and creds.refresh_token:
        creds.refresh(Request())
    else:
        flow = InstalledAppFlow.from_client_secrets_file(
            "credentials.json", SCOPES
        )
        creds = flow.run_local_server(port=0)
    # Save the credentials for the next run
    with open("token.json", "w") as token:
        token.write(creds.to_json())

service = build("admin", "directory_v1", credentials=creds)

# Deactivate users
users_to_deactivate = ["test123@21kschool.school"]
for user_email in users_to_deactivate:
    try:
        # Get the user resource
        user_resource = service.users().get(userKey=user_email).execute()
        
        # Update the 'suspended' field to True (deactivate)
        user_resource["suspended"] = True

        # Update the user
        service.users().update(userKey=user_email, body=user_resource).execute()
        
        print(f"User {user_email} deactivated successfully.")
    except Exception as e:
        print(f"Error deactivating user {user_email}: {e}")

```

if **name** == ‘ **main** ’:  
main()

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [March 20, 2024, 2:54pm UTC](https://community.postman.com/t/postman-api-call-request-to-deactivate-the-google-workspace/55883/8 "2024-03-20T14:54:33Z")

</div>

Closed on March 20, 2024, 2:54pm UTC

This topic was automatically closed after 90 days. New replies are no longer allowed.
