понедельник, 22 марта 2021 г.

Google API - User Get/Create/Delete Automation

 


How to Manage users with Google API calls.


Create OAuth2.0 Credentials

in Google Cloud create credentials


setup the Authorized redirect URIs



Also you'll need to enable Admin SDK



Get Users

Call:      GET https://www.googleapis.com/admin/directory/v1/users?domain=<your domain>

Authorization URL: https://accounts.google.com/o/oauth2/auth

Authorization Token URL: https://accounts.google.com/o/oauth2/token

Client ID: from credentials you created in GCP

Client Secrete: from credentials you created in GCP

Redirect URL: https://www.getpostman.com/oauth2/callback

Then click - Refresh Token


A page to enter email and password will popup. Then you'll have to click Allow.

Once you got your Access Token (will expire in 1 hour) - you can SEND the request


Create Users

Call:      POST https://www.googleapis.com/admin/directory/v1/users

Authorization URL: https://accounts.google.com/o/oauth2/auth

Authorization Token URL: https://accounts.google.com/o/oauth2/token

Client ID: from credentials you created in GCP

Client Secrete: from credentials you created in GCP

Redirect URL: https://www.getpostman.com/oauth2/callback



JSON body:

{

"primaryEmail": "user1@domain.com",

"name": {

 "givenName": "User1",

 "familyName": "Smith"

},

"suspended": false,

"password": "PASSWdfalkjas0d",

"changePasswordAtNextLogin": true,

"ipWhitelisted": false,

"emails": [

 {

  "address": "userlast@gmail.com",

  "type": "home",

  "customType": "",

  "primary": false

 }

],

"addresses": [

 {

  "type": "work",

  "customType": "",

  "streetAddress": "1600 Amphitheatre Parkway",

  "locality": "Mountain View",

  "region": "CA",

  "postalCode": "94043"

 }

],

"organizations": [

 {

  "name": "Department of Technology",

  "title": "SWE",

  "primary": true,

  "type": "work",

  "description": "Software engineer"

 }

],

"phones": [

 {

  "value": "+1 99589559040",

  "type": "home"

 }

],

"includeInGlobalAddressList": true

}


Delete Users

Call:      POST https://www.googleapis.com/admin/directory/v1/users

Authorization URL: https://accounts.google.com/o/oauth2/auth

Authorization Token URL: https://accounts.google.com/o/oauth2/token

Client ID: from credentials you created in GCP

Client Secrete: from credentials you created in GCP

Redirect URL: https://www.getpostman.com/oauth2/callback



In this example Insomnia Rest Api tool is used.

You can use Postman as well.


The list of Scopes:

https://developers.google.com/admin-sdk/directory/v1/guides/authorizing

Google Doc

https://developers.google.com/admin-sdk/directory/v1/guides/manage-users

1 комментарий:

  1. Casino City NJ Review, Promo Codes, Games and Casinos
    Check out the 여주 출장마사지 casino city NJ promo codes 의정부 출장안마 and promo codes. We 서산 출장샵 have the best casino welcome bonuses, no deposit bonus, and 속초 출장안마 other 화성 출장샵 types of online

    ОтветитьУдалить