0

Why am I unable to retrieve a list of users when using query to search the orgUnitPath? When I try the same parameters on the Google API Explorer (https://developers.google.com/admin-sdk/directory/reference/rest/v1/users/list) the response returns the expected result of users. However, in my code, the response returned is undefined because the full response does not seem to be pulled. Code.gs for reference:

function myFunction() {
  var options = {
    domain: schoolDomain, // Google Workspace domain name
    query: orgUnitPath='/School Staff',
    type: 'all',
    maxResults: 5,
    orderBy: 'familyName',
    viewType: 'admin_view'
  };

  var response = AdminDirectory.Users.list(options);
  console.log(response.users);
}
MeesterZee
  • 99
  • 7
  • 1
    I figured out the solution, this should be better documented. The query parameter needs to be wrapped in quotes. The line: query: orgUnitPath='/School Staff' should be written as query: "orgUnitPath='/School Staff'" – MeesterZee Nov 22 '22 at 21:57

1 Answers1

0

I'm writing this answer as a community wiki since the solution was provided by the OP in the comments section.

The issue was related to the syntax of the query, when using the query for orgUnitPath, it needs to be inside '' like this:

"orgUnitPath='/School Staff'" 

or

'orgUnitPath="/School Staff"'

This information can be found in the Google Documentation here.

Giselle Valladares
  • 2,075
  • 1
  • 4
  • 13