'How to use IN clause in Microsoft graph Api

I have two team ids which I want to search in one query. I already tried some possible queries like one blow but nothing working

https://graph.microsoft.com/beta/groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team') and id eq ['13be6971-79db-4f33-9d41-b25589ca25af', '02bd9fd6-8f93-4758-87c3-1fb73740a315]'

this is the error message that this query is giving { "error": { "code": "BadRequest", "message": "Invalid filter clause", "innerError": { "request-id": "ced5a7c7-73a1-49bb-afc1-3f312bac8759", "date": "2019-09-11T08:11:58" } } }

To use graph API explorer you can click here https://developer.microsoft.com/en-us/graph/graph-explorer#



Solution 1:[1]

The in filter operator does not seem to be supported by Graph up to now, hence the error. At least it is not mentioned to be supported in the documentation:

Support for $filter operators varies across Microsoft Graph APIs. The following logical operators are generally supported:

  • equals (eq)
  • not equals (ne)
  • greater than (gt)
  • greater than or equals (ge)
  • less than (lt),
  • less than or equals (le)
  • and (and)
  • or (or)
  • not (not)

If you have a limited set of values for the in clause, you could use eq and or, e.g.

https://graph.microsoft.com/beta/groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team') and (id eq '13be6971-79db-4f33-9d41-b25589ca25af' or id eq '02bd9fd6-8f93-4758-87c3-1fb73740a315')

Solution 2:[2]

Given that you use v1.0 api version instead of beta, then the IN query should be possible:

$filter=displayName in ('group-1', 'group-2')

Full url example after encoding:

https://graph.microsoft.com/v1.0/groups?$filter=displayName%20in%20%28%27group-1%27%2C%20%27group-2%27%29

Btw this was written by hand - I found no Microsoft documentation example how to build IN operator query.

Solution 3:[3]

Found this on Microsoft documentation

List all users whose company name is either undefined or Microsoft. GET ../users?$filter=companyName in (null, 'Microsoft')&$count=true. This is an advanced query.

[https://docs.microsoft.com/en-us/graph/query-parameters#filter-parameter][1]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Markus
Solution 2
Solution 3