Graph API Filter

Abhay Chandramouli 1,026 Reputation points
2023-04-03T08:20:30.12+00:00

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,271 questions
{count} votes

Accepted answer
  1. CarlZhao-MSFT 42,451 Reputation points
    2023-04-04T09:55:26.3433333+00:00

    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.