appwrite list users search params

Issue

I am trying to use appwrite server sdk list users to get userid from an email.

The documentation says there is a search: option that can be used but no where does it say what the format of that String? is.

What is the format of the search: String? to only get a list of users whose email matches?

void main() { // Init SDK
  Client client = Client();
  Users users = Users(client);

  client
    .setEndpoint(endPoint) // Your API Endpoint
    .setProject(projectID) // Your project ID
    .setKey(apiKey) // Your secret API key
  ;

  Future result = users.list(search: '<<<WHAT GOES HERE>>>');
}

Solution

:wave: Hello!

Thanks for bringing this question up, this is definitely not well documented, I’ll note this down and try to make it clearer in the docs, but here’s how you’d approach this in Dart:

  final res = users.list(search: Query.equal('email', 
    'email@example.com'));

  res.then((response) {
    print(response.users[0].toMap());
  }).catchError((error) {
    print(error);
  });

The Query object generates a query string, and works similar to how listDocument would work. The difference here is that it only takes a single query string instead of a list.

Answered By – Vincent Ge

Answer Checked By – Dawn Plyler (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *