Forum Discussion
[Graph API] Filter contacts query by emailAddresses
Hi,
https://developer.microsoft.com/en-us/graph/graph-explorer
I am trying to run a GET query on the `contacts` endpoint, passing in a filter on the `emailAddresses` sub-property, with the aim of returning all contacts where `any` address contains a specified string.
However, it seems this operation is unsupported for sub-properties (at the very least, startswith/endswith/contains, i.e. any partial string matching)? Running the below queries return:
https://graph.microsoft.com/v1.0/me/contacts?$filter=emailAddresses/any(a:contains(a/address,'@gmail'))
If you filter on `givenName` instead (just a regular property), it works great. Additionally, you can match on sub-property if you use `eq` (obviously not sufficient in the context of partial string matching).
https://graph.microsoft.com/v1.0/me/contacts?$filter=contains(givenName , '@gmail')
Just wondering if there is any solution for being able to filter contacts based on partial matching (the only thing I can think of is grabbing every single contact and filtering client side, which is obviously terrible).
I also briefly tried the $search query params, but it seems to be limited to specific resources (not contacts), so unsure if this route works.
This seems like a relatively common use case, so I'm remaining hopeful.
Thanks!
1 Reply
- Not supported, as mentioned in the documentation: https://learn.microsoft.com/en-us/graph/api/user-list-contacts?view=graph-rest-beta&tabs=http#optional-query-parameters
Note that you can use $filter, any, and the eq operator on only the address sub-property of instances in an emailAddresses collection. That is, you cannot filter on the name or any other sub-property of an instance of emailAddresses, nor can you apply any other operator or function with filter, such as ne, le, and startswith().
You can always filter them client-side.