Graph API: How to use $filter in list user?

Wang, Wei 41 Reputation points

Greetings! I just got started learning about Graph API, writing some Node.js code to test things out.

I have registered a developer account that gave me a sand box to play with. I got my script to list users with this simple query:

That gives me the list of all users in my organization. So far so good.

Following the documentation,
I tried to use the filter to find particular users, with:'Wang'
I was hoping to get a list of one user (myself) in return.

But I get the list of all users instead.

Tried a few other filters, like $filter=startsWith(mail,'ww'), still the same results.

What am I doing wrong? Thanks for any advice.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,126 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 39,101 Reputation points

    Hi @Wang, Wei

    Your URL doesn't seem to be decoded, and the encoded part isn't actually recognized. The decoded API endpoints are:$filter=givenName eq 'Wang'  

    By the way, make sure you specify the value of First name as Wang when you create the user, otherwise the endpoint will return an empty array.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Bhanu Kiran 3,526 Reputation points

    Hello @Wang, Wei ,

    To use $filter query parameter for List users using 'givenName', use the following endpoint:

    GET$filter=givenName eq 'name'  


    Please check and validate the same.

    Refer to this document for more information on $filter query parameter

    Hope this helps,
    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    0 comments No comments

  2. Wang, Wei 41 Reputation points

    Thanks for both answers. I guess I didn't experiment enough.

    From the documentations:
    It wasn't quite clear to me that only the <filter-value> part of the "$filter=<filter-value>" is supposed to be encoded.

    Once I got that part right, it started working for me.

    Thanks again!

    0 comments No comments