Is there a way to filter out domains using graph api?

Arden Asher 0 Reputation points
2023-04-04T11:51:50.0966667+00:00

Hello, Is there a way to exclude certain mails from specific domains to not syncing over the API? I tried with $filter with the ne and null operator, but it didn’t work. I love to making this work at the API level or scope permissions instead of at the app logic level.

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-04-04T12:35:20.0866667+00:00

    Hello Arden Asher,

    Thanks for reaching out!

    You can use $filter to get all users with a mail that ends with '******@domain.com', including a count of returned objects, with the results ordered by userPrincipalName.

    To negate the result of the expression inside this clause, use the not operator, not the ne operator. For example, the following query retrieves only users whose domain does not end with @contoso.com.

    GET https://graph.microsoft.com/v1.0/users?$filter=not(mail,'******@contoso.com')&$orderby=userPrincipalName&$count=true
    ConsistencyLevel: eventual
    

    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

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.