3

The documentation states:

Query string for prefix matching searches. Should be of the form "key":"value" where key can be "email", "firstName" or "lastName".

I've tried:

directory.users().list().setQuery("email:" + email).execute()

directory.users().list().setQuery("\"email\":\"" + email + "\"").execute()

directory.users().list().setQuery("email:\"" + email + "\"").execute()

They all return a 400 : Bad Request response. How do I properly filter on the email address? Thank you!

piusvelte
  • 1,596
  • 2
  • 15
  • 18

3 Answers3

2

Here's the way to get a user by email address.

directory.users().get(userKey=email).execute()

Code to search for a user by email address should be something like

directory.users().list(query='email:emily@example.com').execute()

but this doesn't work. I suspect a bug in Google's API docs, or possibly in the actual implementation.

  • Good to know I'm not crazy. Thought I was misunderstanding the docs, but a .list() query like that does return error 400. I can get the current job done with .get() but how annoying. Also amazing that this bug is currently at least two years old! – shacker Sep 28 '15 at 21:36
2

Currently the list API supports only prefix queries, please refer to the documentation for query parameter here.

Try with query as "email:someEmail@someDomain.com*" -> Note the asterisk at the end.

0

maybe this will point you in the right direction:

    var listReq = service.Users.List();
            listReq.Domain = domain;
        Users results = listReq.Execute();
JoBe
  • 391
  • 3
  • 12