Forum Discussion

henryg124's avatar
henryg124
Copper Contributor
Sep 27, 2024

[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')) 

{
    "error": {
        "code": "ErrorInvalidUrlQueryFilter",
        "message": "The query filter contains one or more invalid nodes."
    }
}


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

Resources