How to get only specific fields with Google Directory API users.list

Viewed 350

The documentation (https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list#query-parameters) says you can use customFieldMask to get only specific fields. I cannot figure out the format/structure of this property.

For example, given this for a user:

{
  "kind": "admin#directory#user",
  "id": "...",
  "etag": "\"...\"",
  "primaryEmail": "...",
  "name": {
    "givenName": "...",
    "familyName": "...",
    "fullName": "......"
  },
  "emails": [
    {
      "address": "...",
      "primary": true
    }
  ]
}

I only want to get primaryEmail but I can't figure out how.

2 Answers

Send "users(primaryEmail)" in the fields parameter, not in the customFieldMask parameter.

The Directory API can't retrieve the 'primaryEmail' with the customFieldMask attribute, with this attribute you can only specify the custom schema names that you create in the Admin console.

Related