0

I'm trying to do two things:

  • Query AdminDirectory.Users.list by name field to return a list of anyone whose name matches a given string (even partially)
  • If possible, prevent the email address field from being included in the search

For example, "donald" should return data for the users Donald Duck, Donald Trump, and Ronald McDonald. If someone searched for "onald", that should work too.

The below sort of works. In the "donald" scenario, it would return only Donald Duck's data. For some reason it won't return more than one user.

function processForm(formObject) { // formObject comes from form on front end
    var textSearchObject = formObject.textSearch; // "donald"

    var userList = AdminDirectory.Users.list({
        domain: 'somedomain.com',
        query: "name:'" + textSearchObject + "'",
        viewType: 'domain_public',
        projection: 'full'
    }).users;

    return userList;
}

I know, query: "name:'" + textSearchObject + "'" looks very strange and most people would just use query: textSearchObject. The problem is that this searches email addresses - I need to avoid this if possible.

friendofdog
  • 79
  • 12
  • I believe you may need to put wildcards on either side of textSearchObject such as: `query: "name:'*" + textSearchObject + "*'",` – Karl_S Apr 03 '17 at 12:42
  • The asterix breaks the code... – friendofdog Apr 05 '17 at 01:39
  • @PeterHerrmann, you're right! It's right there in the link you provided, very easy to miss in the documentation: `The field starts with the value. For example, a query with givenName:Jane* matches users with givenName values of "Jane", "Jane Ann", and "Janet" but not "Sarah Jane".` – friendofdog Apr 11 '17 at 05:15

1 Answers1

0

You're limited to "starts with" searching e.g. Donald* but you can search just the givenName, familyName or the combined name (fullName). Full documentation is here: https://developers.google.com/admin-sdk/directory/v1/guides/search-users

Peter
  • 5,501
  • 2
  • 26
  • 42