Share via

Graph API Filter

Abhay Chandramouli 1,031 Reputation points
Apr 3, 2023, 8:20 AM

Hi,

I need to filter users in adb2c where the value of state field is not set i.e = null (not in string but just null)

null and not "null"

Let me know the graph api query to achieve this

I have been stuck for a week

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,440 questions
{count} votes

Accepted answer
  1. CarlZhao-MSFT 43,011 Reputation points
    Apr 4, 2023, 9:55 AM

    Hi @Abhay Chandramouli

    Azure AD B2C does not support advanced queries, this is a known issue, so don't try to filter using the advanced query feature of the $filter query parameter. User's image

    The currently available method is to filter the user set using the graph C# SDK, please refer to my code snippet:

    try 
    {
          var result = await graphServiceClient.Users.GetAsync();
    
          var userList = result.Value;
    
          for (int i = 0; i < userList.Count; i++) {
    
          if (userList[i].State == null) {
    
                var user = new Dictionary<string, object>();
    
                user.Add("id", userList[i].Id);
                user.Add("displayName", userList[i].DisplayName);
                user.Add("state", userList[i].State);
    
          Console.WriteLine(JsonConvert.SerializeObject(user));   
         
            }
        } 
    }
    catch (ODataError odataError)
    {
          Console.WriteLine(odataError.Error.Code);
          Console.WriteLine(odataError.Error.Message);
    }
    
    

    User's image

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

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.