Search code examples
google-apps-scriptgoogle-people-api

Google People API contactGroups.list not working


I am trying to retrieve a simple JSON file with label names + resource names from Google Contacts using Apps Script, for which I have written the following:

function getAllMemberships() {
    var request = People.People.contactGroups.list('people/me',{
        groupFields: 'name'});
    Logger.log(request.contactGroups);
}

But keep receiving the same error:

TypeError: Cannot read properties of undefined (reading 'list')

For the second line of code. I have activated the People Service (identifier 'People') and given all permissions, but have no clue why the method does not work. Any advice/lead?


Solution

  • Try this modification:

    function getAllMemberships() {
        var request = People.ContactGroups.list({
          "groupFields": "name"
        });
        Logger.log(request.contactGroups);
    }
    

    Guide/Reference: https://developers.google.com/apps-script/advanced/people

    Sample: Result Logs image