Add an user on Google group

Manifest

{
    "form": [
        {
            "id": "GROUP",
            "name": "Time",
            "type": "choice",
            "items": [
                {
                    "key": "<group 1 id>",
                    "value": "group 1"
                },
                {
                    "key": "<group 2 id>",
                    "value": "group 2"
                }
            ],
            "method": "GET",
            "choice_name": "value",
            "choice_value": "key",
            "options_source": "fixed list",
            "cast_data_to_json": true
        }
    ],
    "oauth": {
        "refresh": {
            "url": "https://oauth2.googleapis.com/token",
            "data": {
                "client_id": "{{ CLIENT_ID }}",
                "grant_type": "refresh_token",
                "client_secret": "{{ CLIENT_SECRET }}",
                "refresh_token": "{{ oauth.refresh_token }}"
            },
            "method": "POST",
            "cast_data_to_json": false
        },
        "access_token": {
            "url": "https://oauth2.googleapis.com/token?client_id={{CLIENT_ID}}&client_secret={{CLIENT_SECRET}}&grant_type=authorization_code&redirect_uri={{redirect_url}}",
            "method": "POST"
        },
        "authenticate_url": "https://accounts.google.com/o/oauth2/v2/auth?client_id={{CLIENT_ID}}&redirect_uri={{redirect_url}}&response_type=code&scope=https://www.googleapis.com/auth/admin.directory.user https://www.googleapis.com/auth/admin.directory.group.member https://www.googleapis.com/auth/admin.directory.group&access_type=offline&prompt=consent"
    },
    "execute": [
        {
            "url": "https://admin.googleapis.com/admin/directory/v1/groups/{{GROUP}}/members",
            "data": {
                "kind": "admin#directory#member",
                "role": "MEMBER",
                "type": "USER",
                "email": "{{ email }}"
            },
            "method": "POST",
            "cast_data_to_json": false
        }
    ],
    "headers": {
        "Accept": "application/json",
        "Content-Type": "application/json",
        "Authorization": "Bearer {{ oauth.access_token }}"
    },
    "initial_data_form": [
        {
            "id": "CLIENT_ID",
            "name": "The Google client id",
            "description": "You can find it here: "
        },
        {
            "id": "CLIENT_SECRET",
            "name": "The Google client secret",
            "description": "You can find it here: "
        }
    ]
}

API definition: https://developers.google.com/admin-sdk/directory/reference/rest/v1/members/insert

Heads-up: check on API definition scopes that are need

Comments

No comments yet.