1
votes

I'm working with the ms graph contacts api and looking for filter options

Is it possible to filter contacts that has at least one element in emailadresses or buisnessphones?.

I have already tried something like $filter=emailAddresses/$count gt 0'

1

1 Answers

1
votes

$count is only working on the contacts level and according to this document , $filter is not supported for emailadresses or buisnessphones yet.

As a workaround , you could filter the results from the contacts collection using c# /javascript . For example in c#:

using (var request = new HttpRequestMessage(HttpMethod.Get, "https://graph.microsoft.com/v1.0/me/contacts"))
{
    request.Headers.Add("Authorization", "Bearer " + token);
    request.Headers.Add("Accept", "application/json;odata.metadata=minimal");

    using (var response = client.SendAsync(request).Result)
    {

        if (response.StatusCode == HttpStatusCode.OK)
        {
            var model = JsonConvert.DeserializeObject<RootObject>(response.Content.ReadAsStringAsync().Result);
            foreach (var item in model.value)
            {
                if (item.BusinessPhones.Count>0)
                {
                    //you could add this contact to a contact list .
                }
            }
          

        }

    }
}

public class RootObject
{

    public List<Value> value { get; set; }
}

public class Value
{
    public string id { get; set; }
    public List<object> BusinessPhones { get; set; }
    public List<object> EmailAddresses { get; set; }
}